每个核心数据关系是否必须有反向? [英] Does every Core Data Relationship have to have an Inverse?

查看:114
本文介绍了每个核心数据关系是否必须有反向?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有两个Entity类: SocialApp SocialAppType

Let's say I have two Entity classes: SocialApp and SocialAppType

SocialApp 我有一个属性: appURL 和一个关系:

In SocialApp I have one Attribute: appURL and one Relationship: type.

SocialAppType 我有三个属性: baseURL name favicon

In SocialAppType I have three Attributes: baseURL, name and favicon.

SocialApp 关系类型的目的地是 SocialAppType

The destination of the SocialApp relationship type is a single record in SocialAppType.

例如,对于多个Flickr帐户,会有一些 SocialApp 记录,每个记录包含一个人的帐户的链接。对于Flickr类型,将有一个 SocialAppType 记录,所有 SocialApp 记录将指向

As an example, for multiple Flickr accounts, there would be a number of SocialApp records, with each record holding a link to a person's account. There would be one SocialAppType record for the "Flickr" type, that all SocialApp records would point to.

当我用这个模式构建一个应用程序时,我得到一个警告,在 SocialAppType SocialApp

When I build an application with this schema, I get a warning that there is no inverse relationship between SocialAppType and SocialApp.

 /Users/username/Developer/objc/TestApp/TestApp.xcdatamodel:SocialApp.type: warning: SocialApp.type -- relationship does not have an inverse

一个逆,为什么?

推荐答案

在实践中,我没有任何数据丢失,至少我知道。 Google建议您快速使用它们:

In practice, I haven't had any data loss due to not having an inverse - at least that I am aware of. A quick Google suggests you should use them:


反向关系不只是
使事情更加整洁,实际上是$核心数据使用的b $ b维护数据
的完整性。

An inverse relationship doesn't just make things more tidy, it's actually used by Core Data to maintain data integrity.

- Cocoa Dev Central



两个方向的关系,
适当地指定反向关系
。如果更改是
,Core Data使用此
信息来确保对象图的一致性
(请参阅操作关系
和对象图完整性)。对于
讨论一些原因,为什么
你可能不想在两个方向建模
关系,和
一些可能出现的问题
if你不会,请参阅单向
关系。

You should typically model relationships in both directions, and specify the inverse relationships appropriately. Core Data uses this information to ensure the consistency of the object graph if a change is made (see "Manipulating Relationships and Object Graph Integrity"). For a discussion of some of the reasons why you might want to not model a relationship in both directions, and some of the problems that might arise if you don’t, see "Unidirectional Relationships."

- 核心数据编程指南

这篇关于每个核心数据关系是否必须有反向?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆