Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/79.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 核心数据:3表连接?_Iphone_Sql_Ipad_Core Data - Fatal编程技术网

Iphone 核心数据:3表连接?

Iphone 核心数据:3表连接?,iphone,sql,ipad,core-data,Iphone,Sql,Ipad,Core Data,我知道核心数据不是一个数据库,有很多不同之处。是这个吗 在数据库中,我通常会有以下内容 A->>B->>C A有很多B,B有很多C “给我所有具有c.attr='X'的A”的查询很容易写成: select * from a, b, c where a.id = b.aid and b.id = c.bid and c.attr = 'X' 在Core Data中,我也希望这样做,但使用如下谓词: NSPredicate *predicate = [NSPredicate predicat

我知道核心数据不是一个数据库,有很多不同之处。是这个吗

在数据库中,我通常会有以下内容

A->>B->>C

A有很多B,B有很多C

“给我所有具有c.attr='X'的A”的查询很容易写成:

select * from a, b, c where a.id = b.aid and b.id = c.bid and c.attr = 'X'
在Core Data中,我也希望这样做,但使用如下谓词:

NSPredicate *predicate = 
  [NSPredicate predicateWithFormat:@"ANY bs.cs.attr = %@", "X"];
[frequest setEntity:entityA];
[frequest setPredicate:predicate];
这样做会导致错误: “NSInvalidArgumentException”,原因:“此处不允许使用多对多键”

我是否正确地解释为数据库称之为多表联接存在限制

我在谷歌上四处搜索,找不到确切的答案

我当前对此查询的解决方案如下所示:

NSPredicate *predicate = 
  [NSPredicate predicateWithFormat:@"ANY cs.attr = %@", "X"];
...
NSArray *bs = //execute fetch
for (B *b in bs) {
  //add b.a into an array
}
//return array

有更好的办法吗?提前谢谢你的考虑。

你把这件事往后推

首先,核心数据中不需要链接id,因为所有相关对象都已通过关系链接。这意味着根本不需要像
这样的构造,其中a.id=b.aid和b.id=c.bid

其次,您通常为接收定义测试的实体设置fetch实体。在这种情况下,即
c.attr=“X”
,因此,您将fetch实体设置为
c
,您的谓词应该如下所示:

NSPredicate *p=[NSPredicate predicateWithFormat:@"attr=%@",xValue];
这将返回满足测试的所有
C
实例的数组。然后查找任何特定的
B
A
只需遍历每个
C
的关系即可

如果您的反向关系是一个,例如A>B>C,那么您只需向每个
C
询问
B.A
的值,因此:

AObject *anA = aCinstance.b.a;

重要的是要记住,您在这里不是在处理表。您是在处理对象图。您将获取设置为特定实体,然后遍历过滤实体的关系。

核心数据是否可以为b和a的属性添加测试?或者我必须依次迭代每个结果集以获得m最终结果如何

select 
  p.id, p.total 
from 
  purcord p, line l, delivery d 
where 
  l.purcord_id = p.id
  and d.purcord_id = l.purcord_id
  and d.purcord_line_no = l.line_no
  and d.status = 'notdelivered'
  and l.status = 'open'
  and p.status = 'open'

啊,a,b,c连接语法是邪恶的。