我有模型(简化):
class _User {
int id;
@Relate(#users)
Currency currency;
}
class _Currency {
int id;
ManagedSet<Price> prices;
ManagedSet<User> users;
}
class _Price {
int id;
@Relate(#prices)
Currency currency;
ManagedSet<DefaultPrice> defaultPrices;
}
class _Game {
int id;
String code;
}
class _DefaultPrice {
int id;
@Relate(#defaultPrices)
Price price;
@Relate(#defaultPrices)
EventTemplate eventTemplate;
}
class _EventTemplate {
int id;
ManagedSet<DefaultPrice> defaultPrices;
@Relate(#eventTemplates)
Game game;
}
现在我想获取包含特定价格但仅包含特定货币的特定游戏的所有事件模板。
要解决此问题,我在控制器中使用以下代码:
final String gameCode = request.path.variables['gameCode'];
final User user = request.attachments['user'];
final eventTemplatesQuery = Query<EventTemplate>(database)
..where((eventTemplate) => eventTemplate.game.code).equalTo(gameCode);
eventTemplatesQuery.join(set: (eventTemplate) => eventTemplate.defaultPrices)
..where((defaultPrice) => defaultPrice.price.currency.id).equalTo(user.currency.id);
// ..where((defaultPrice) => defaultPrice.price.currency).identifiedBy(user.currency.id); // the same result
final eventTemplates = await eventTemplatesQuery.fetch();
我希望将选择所有事件模板,并按游戏代码进行过滤,然后将加入按货币过滤的默认价格。但是相反,我得到一个错误:
[FINE] aqueduct: Query (8ms) SELECT t0.id,t0.code,t0.description,t0.createdAt,t0.updatedAt,t0.game_id,t1.id,t1.createdAt,t1.updatedAt,t1.eventTemplate_id,t1.price_id FROM _EventTemplate t0 LEFT OUTER JOIN _DefaultPrice t1 ON (t0.id=t1.eventTemplate_id AND t3.id = @t1t3_id:int8) LEFT OUTER JOIN _Price t2 ON t1.price_id=t2.id LEFT OUTER JOIN _Currency t3 ON t2.currency_id=t3.id LEFT OUTER JOIN _Game t4 ON t0.game_id=t4.id WHERE t4.code LIKE @t0t4_code:text {t0t4_code: SM, t1t3_id: 8}
[WARNING] aqueduct: PostgreSQLSeverity.error 42P01: missing FROM-clause entry for table "t3"
[SEVERE] aqueduct: POST {{ request.toDebugString() }} PostgreSQLSeverity.error 42P01: missing FROM-clause entry for table "t3"
看起来像渡槽ORM不能使用嵌套的JOIN进行过滤,但是documentation中没有关于这种情况下的限制或限制的信息。
Aqueduct CLI version: 3.1.0+1
Dart VM version: 2.1.0 (Tue Nov 13 18:22:02 2018 +0100) on "windows_x64"
postgres (PostgreSQL) 10.6 (Ubuntu 10.6-1.pgdg18.04+1)