iPhone核心数据递归关系

发布于 2024-08-11 06:55:59 字数 574 浏览 3 评论 0原文

我在核心数据中的递归关系方面遇到了一些麻烦。我有一个名为“SearchCategory”的托管对象,该类别可以有“类别”,也可以有“类别”。在托管对象建模器中,我在 SearchCategory 实体上设置了两个关系,并且都指向 SearchCategory 实体 - 一个名为“类别”并且是一对多关系。另一个是“类别”,不是对多,并且是“类别”的逆。

在我的代码中,我使用“setCategoriesObject”将类别添加到搜索类别,这似乎有效。但是,当我说 [mySearchCategory setCategory:aParentCategory] 时,其中 mySearchCategory 将是 aParentCategory 的子类别,它似乎不想要记在记忆里。如果我运行上面的代码,那么[managementobjectcontext save:&err],它实际上是把父类别的主键保存到数据库中子类别的“Category”字段中,但是Core数据不会在运行时综合此关系,因此 [mySearchCategory Category] 返回 nil。这里有什么想法吗?

I'm having some trouble with a recursive relationship in core data. I've got a managed object called a "SearchCategory", and that category can have "Categories" and it can also have a "Category." In the managed object modeler, I've got two relationships set up on the SearchCategory entity, and both point back to the SearchCategory entity - one is named "Categories" and is a to-many relationship. The other is "Category", is not a to-many, and is the inverse of "Categories."

In my code I'm using "setCategoriesObject" to add categories to a searchcategory, which seems to be working. However, when I say [mySearchCategory setCategory:aParentCategory], where mySearchCategory would be a child category of aParentCategory, it doesn't seem to want take in memory. If I run the above code, then [managedobjectcontext save:&err], it actually saves the primary key of the parent category to the "Category" field of the child category in the database, but Core Data doesn't synthesize this relationship at run time, so [mySearchCategory Category] returns nil. Any thoughts here?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

初懵 2024-08-18 06:55:59

事实证明我错误地解释了我看到的结果。事实上,这种关系运转良好,但我看待它的方式却让我觉得情况并非如此。抱歉,出现了虚假问题:(

Turns out I was interpreting the results I was seeing incorrectly. The relationship was in fact working properly, but the way I was looking at it made it seem that it wasn't. Sorry for the bogus problem :(

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文