iPhone核心数据递归关系
我在核心数据中的递归关系方面遇到了一些麻烦。我有一个名为“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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
事实证明我错误地解释了我看到的结果。事实上,这种关系运转良好,但我看待它的方式却让我觉得情况并非如此。抱歉,出现了虚假问题:(
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 :(