English 中文(简体)
iPhone Core Data Recursive Relationships
原标题:

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?

问题回答

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 :(





相关问题
Recursive same-table query in SQL Server 2008

I have the following table in a SQL Server 2008 database: Id Name ParentFolder -- ---- ------------ 1 Europe NULL 2 Asia NULL 3 Germany 1 4 UK 1 5 China ...

Finding a class within list

I have a class (Node) which has a property of SubNodes which is a List of the Node class I have a list of Nodes (of which each Node may or may not have a list of SubNodes within itself) I need to be ...

Selecting records during recursive stored procedure

I ve got a content management system that contains a hierarchical structure of categories, with sub-categories subject to different ordering options at each level. Currently, that s retrieved by a (...

热门标签