如何避免核心数据警告“实体应该有反向关系”? [英] How to avoid Core Data warning "Entity should have an inverse relationship"?

查看:349
本文介绍了如何避免核心数据警告“实体应该有反向关系”?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个模型图,其中有几个实体与其他实体有一对多的关系。

这意味着反向关系应该是一对多,但这是不可能的。

I have a model graph, where there is several entities that have one to many relationship with other entity.
It means that inverse relationship should be one to many, but that is impossible.

核心数据工作良好,没有反向关系,唯一让我疯狂的事是警告)

The core data works well without inverse relationship, The only thing that drives me crazy is warnings)

做某人知道以避免这些特定的警告?

Do somebody know how to avoid these specific warnings?

感谢。

推荐答案

反相关系

大多数关系都是双向的。如果部门与在部门中工作的员工具有一对多关系,则员工与部门之间存在反向关系。主要的例外是获取的属性,它表示一个弱的单向关系 - 从目的地到源没有关系(见获取的属性)。

Most relationships are inherently bi-directional. If a Department has a to-many relationship to the Employees that work in a Department, there is an inverse relationship from an Employee to the Department. The major exception is a fetched property, which represents a weak one-way relationship—there is no relationship from the destination to the source (see "Fetched Properties").

您通常应该在两个方向上建模关系,并适当地指定反向关系。如果发生更改,Core Data使用此信息确保对象图的一致性

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

引用苹果文档

已编辑:

作为一般规则,一对多关系具有多对一的逆。如果你想定义一个多对多关系,你只需要将一个关系定义为to-many,并将它的inverse定义为to-many。

As a general rule, a one-to-many relation has a many-to-one inverse. In case you want to define a many-to-many relationship, you simply define one relation as to-many and its inverse as a to-many as well.

这篇关于如何避免核心数据警告“实体应该有反向关系”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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