核心数据关系设置
Core Data Relationship settings
我正在创建一个获取实体 "Plan" 和 "Tool" 的应用程序。 "Tool" 必须是唯一的,并且工具会链接到不同的计划。例如,计划 "A" 获得了工具 "a"、"b" 和 "c"。另一个计划 "B" 获得了工具 "b"、"c" 和 "d"。所以 "b" 和 "c" 都在 "A" 和 "B" 中。所以一个工具可以链接到更多的计划。
如何处理核心数据关系?
我尝试了一些不同的设置并使用 "DB Browser for SQLite" 观察了数据库,但它没有像我想的那样工作。
示例:
我的关系必须有哪些设置?
Many-to-Many Relationships
You define a many-to-many relationship using two to-many
relationships. The first to-many relationship goes from the first
entity (the source entity) to the second entity (the destination). The
second to-many relationship goes from the second entity (the original
destination entity) to the first entity (the original source entity).
You then set each to be the inverse of the other.
在你的情况下应该是这样的:
在这里您可以看到关系属性:
同样,来自 Apple 的文档:
IMPORTANT
You must define many-to-many relationships in both directions—that is,
you must specify two relationships, each being the inverse of the
other. You can’t just define a to-many relationship in one direction
and try to use it as a many-to-many. If you do, you will end up with
referential integrity problems.
我正在创建一个获取实体 "Plan" 和 "Tool" 的应用程序。 "Tool" 必须是唯一的,并且工具会链接到不同的计划。例如,计划 "A" 获得了工具 "a"、"b" 和 "c"。另一个计划 "B" 获得了工具 "b"、"c" 和 "d"。所以 "b" 和 "c" 都在 "A" 和 "B" 中。所以一个工具可以链接到更多的计划。
如何处理核心数据关系? 我尝试了一些不同的设置并使用 "DB Browser for SQLite" 观察了数据库,但它没有像我想的那样工作。
示例:
我的关系必须有哪些设置?
Many-to-Many Relationships
You define a many-to-many relationship using two to-many relationships. The first to-many relationship goes from the first entity (the source entity) to the second entity (the destination). The second to-many relationship goes from the second entity (the original destination entity) to the first entity (the original source entity). You then set each to be the inverse of the other.
在你的情况下应该是这样的:
在这里您可以看到关系属性:
同样,来自 Apple 的文档:
IMPORTANT
You must define many-to-many relationships in both directions—that is, you must specify two relationships, each being the inverse of the other. You can’t just define a to-many relationship in one direction and try to use it as a many-to-many. If you do, you will end up with referential integrity problems.