문제

I'm trying to create search interface via ORMLite in Android. There are 3 tables created, that are making many-to-many relationship. (Recipe >> RecipesForTag << Tag)

tagQueryBuilder.where()
    .like(Tag.COLUMN_NAME, "%" + text + "%");

recipesForTagQueryBuilder
    .joinOr(tagQueryBuilder);

recipeQueryBuilder
    .joinOr(recipesForTagQueryBuilder)
    ...other joins
    .where()
    .like(Recipe.COLUMN_TITLE, "%" + text + "%");

PreparedQuery<Recipe> preparedQuery = recipeQueryBuilder.prepare();

return recipeDao.query(preparedQuery);

When I'm not using line with .joinOr(recipesForTagQueryBuilder) everything is working fine. So what am I doing wrong?

도움이 되었습니까?

해결책

OK my bad. The only thing that was bad was using joinOr while I needed leftJoinOr... The question has one main problem: when middle table is empty no result will be find (also when ...other joins is nonempty). So result is simple:

recipesForTagQueryBuilder
    .leftJoinOr(tagQueryBuilder);

recipeQueryBuilder
    .leftJoinOr(recipesForTagQueryBuilder)
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top