Here's the crux of your problem:
@"isSync == 0 AND SUBQUERY(toBookOrders, $x, $x.toBook == SELF)"
If you split that up into the two subpredicates, as Scott suggests, you'll get:
isSync == 0
SUBQUERY(toBookOrders, $x, $x.toBook == SELF)
The problem is that every SUBQUERY
does not return true or false, as a predicate must. It returns a collection (an array), and an array is not the same thing as true or false. Thus, when you create the predicate, you're getting an error that it's an invalid format, because the stuff after the AND
isn't a predicate. It's simply an expression.
You're probably wanting:
@"isSync == 0 AND SUBQUERY(toBookOrders, $x, $x.toBook == SELF).@count > 0"
This would give you a predicate to find all the books where isSync
is false and the at least one of the Book's OrderBooks
is that Book.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…