QueryBuilder<Answer, Integer> queryBuilder = helper.getAnswerDao().queryBuilder();
QueryBuilder<Question, Integer> questionQueryBuilder = helper.getQuestionDao().queryBuilder();
questionQueryBuilder.where().eq(Question.TYPE_COLUMN_NAME, "table");
queryBuilder.leftJoin(questionQueryBuilder);
queryBuilder.where().eq(Answer.PICKED_COLUMN_NAME, true);
pickedAnswers = queryBuilder.query();
生成的SQL语句:
SELECT `Answers`.*
FROM `Answers`
LEFT JOIN `Questions` ON `Answers`.`questionId` = `Questions`.`id`
WHERE `Answers`.`picked` = 1
AND (`Questions`.`type` = 'table' )
由于'AND'逻辑运算,此查询返回空结果集。这是ORMLite的默认行为。是否有可能通过'OR'操作来改变子句?
在所有queryBuilder.where().or()
方法之后,我在queryBuilder.where().eq(Answer.PICKED_COLUMN_NAME, true)
和queryBuilder.where().or(2)
之前尝试过:where()
。
答案 0 :(得分:5)
有leftJoinOr
方法可以完全满足我的需要。它使用OR逻辑运算构建where子句。