如何在 ORMLite 中构建查询,以便我可以使用 orderBy 函数(使用带有原始字符串的函数或参数化的函数)引用与我正在构建查询的 dao 不同的实体的属性? 我的查询是这样构建的:
// Inner query for performances
QueryBuilder<Performance, String> performancesQB = performanceDao.queryBuilder();
performancesQB.selectColumns("performance_id");
SelectArg performanceSelectArg = new SelectArg();
performancesQB.where().lt("date", performanceSelectArg);
// Outer query for Order objects, where the id matches in the performance_id
// from the inner query
QueryBuilder<Order, String> ordersQB = orderDao.queryBuilder();
ordersQB.where().isNull("user_id").and().in("performance_id", performancesQB);
ordersQB.orderByRaw("performances.date DESC");
pastOrdersQuery = ordersQB.prepare();
每当我尝试执行此查询时遇到的异常是:
android.database.sqlite.SQLiteException: no such column: performances.date:,
while compiling: SELECT * FROM `orders` WHERE
(`user_id` IS NULL AND `performance_id` IN
(SELECT `performance_id` FROM `performances` WHERE `date` < ? ) )
ORDER BY performances.date DESC
我在这里看到的唯一解决方案是自己使用 JOIN 而不是嵌套选择编写原始查询。这可能是一个很好的解决方案吗?