使用具有多个属性的 SUBQUERY
Using SUBQUERY with multiple attributes
我有3个实体,"Bar","Waiter","Product"关系如下,一个"Bar"和"Waiter"一对多关系从 Waiter 到 Product 也是如此。
我需要知道哪些酒吧一直在提供具有特定属性的产品。
我正在获取的实体是 Bars,
到目前为止我已经尝试过:
[NSPredicate predicateWithFormat:@"SUBQUERY(toWaiter, $x, ANY $x.toProduct.dateServed > %@ AND $x.toProduct.dateConsumed > %@).@count > 0), [NSDate date], [NSDate date]];
我在哪里
Only allowed one toMany/manyToMany relationship in subquery expression collection
如果我尝试:
[NSPredicate predicateWithFormat:@"SUBQUERY(toWaiter, $x, ANY $x.toProduct.dateServed > %@ ANY AND $x.toProduct.dateConsumed > %@).@count > 0), [NSDate date], [NSDate date]];
两次 ANY,我得到同样的错误,
Only allowed one toMany/manyToMany relationship in subquery expression collection
子查询多个属性的正确方法是什么?
谢谢。
这是型号:
您可以通过将两个 SUBQUERY 子句嵌套在一起来实现:
NSPredicate *filter = [NSPredicate predicateWithFormat:@"SUBQUERY(toWaiter, $x, SUBQUERY($x.toProduct, $y, $y.dateServed > %@ AND $y.dateConsumed > %@).@count > 0).@count > 0", [NSDate date], [NSDate date]];
或者,用(模糊的)自然语言:"fetch all the Bars
with a non-zero count of (Waiters
with a non-zero count of (Products
with both dateServed
and dateConsumed
greater than today))"。
我有3个实体,"Bar","Waiter","Product"关系如下,一个"Bar"和"Waiter"一对多关系从 Waiter 到 Product 也是如此。
我需要知道哪些酒吧一直在提供具有特定属性的产品。
我正在获取的实体是 Bars, 到目前为止我已经尝试过:
[NSPredicate predicateWithFormat:@"SUBQUERY(toWaiter, $x, ANY $x.toProduct.dateServed > %@ AND $x.toProduct.dateConsumed > %@).@count > 0), [NSDate date], [NSDate date]];
我在哪里
Only allowed one toMany/manyToMany relationship in subquery expression collection
如果我尝试:
[NSPredicate predicateWithFormat:@"SUBQUERY(toWaiter, $x, ANY $x.toProduct.dateServed > %@ ANY AND $x.toProduct.dateConsumed > %@).@count > 0), [NSDate date], [NSDate date]];
两次 ANY,我得到同样的错误,
Only allowed one toMany/manyToMany relationship in subquery expression collection
子查询多个属性的正确方法是什么?
谢谢。
这是型号:
您可以通过将两个 SUBQUERY 子句嵌套在一起来实现:
NSPredicate *filter = [NSPredicate predicateWithFormat:@"SUBQUERY(toWaiter, $x, SUBQUERY($x.toProduct, $y, $y.dateServed > %@ AND $y.dateConsumed > %@).@count > 0).@count > 0", [NSDate date], [NSDate date]];
或者,用(模糊的)自然语言:"fetch all the Bars
with a non-zero count of (Waiters
with a non-zero count of (Products
with both dateServed
and dateConsumed
greater than today))"。