简体   繁体   中英

This SQL in Core-Data

I have two entities, A and B.

A has to-Many relation with B.

One B has always One A, but an A can be related to many B.

The SQL would be this, without joins for a better simplification:

SELECT a.id, a.name FROM a WHERE a.id IN (SELECT distinct(b.id_a) FROM b)

As I import those rows from an .xml file the first time, I can easly add a field in A and just update it if there are rows related from b. The fetched would be easy using this new field in the NSPredicate:

    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"has_b = %@",YES];

but I would like to know if this is really possible without too much extra work.

thanks,

m.

如果您的一对多关系访问器称为my_bees,请尝试:

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"my_bees.@count > 0"];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM