简体   繁体   English

核心数据中的此SQL

[英]This SQL in Core-Data

I have two entities, A and B. 我有两个实体,A和B。

A has to-Many relation with B. A与B有多对多关系。

One B has always One A, but an A can be related to many B. 一个B始终有一个A,但是一个A可以与多个B相关。

The SQL would be this, without joins for a better simplification: SQL将是这样,没有连接的情况下可以进行更好的简化:

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. 当我第一次从.xml文件导入这些行时,我可以轻松地在A中添加一个字段,如果有与b相关的行,则只需对其进行更新。 The fetched would be easy using this new field in the NSPredicate: 使用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"];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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