Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
538 views
in Technique[技术] by (71.8m points)

iphone - SUBQUERY in core data

I can't understand what's wrong with my predication. I have the next database scheme:

DataItem(color_ids) <->> (dataItem)Color

Where Color contains colorID(int).

I tried to get

all DataItems that contain colorID == 5.

I have used the next predicate:

SUBQUERY(color_ids, $sub, $sub.colorID==5).@count > 0

Thanks for your help.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You don't need SUBQUERY for this. In fact, you almost never need SUBQUERY; it is extremely rare to find a situation where it is the correct thing to use.

You can do this instead:

[NSPredicate predicateWithFormat:@"ANY color_ids.colorID == 5"];

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...