How to bind NSTreeController's Children to Core Data ordered to-many-relationship?
Asked Answered
U

1

9

Apple introduced ordered to-many-relationships in Core Data in Lion. I created an entity named TreeNode with an 1:1-object-relation, a 1:1-parent-relation and an ordered to-many-relationship children.

Then I have an NSTreeController with the children key path set to TreeNode.children. Running the application only shows first level elements. So children is not working. Since children is an ordered to-many-relationship, the corresponding class has an NSOrderedSet children. I added a custom method

- (NSArray *) childrenArray {
  return [children array];
}

to TreeNode which works. I could not find any documentation concerning that topic. Is it really the way to go when binding NSTreeController to an ordered to-many-relationship? Thanks in advance.

Unfledged answered 12/8, 2011 at 11:2 Comment(3)
I haven't used ordered relationships like this yet but tree controllers have always been notoriously fussy. I would suggest getting it to work without the ordering first and then add the ordering.Sabotage
I'm having the same issue as well. Is there any working example of NSTreeController working together with Ordered CoreData relationships?Merciless
Simply adding the childrenArray method solved the problem for me!Arabinose
S
4

It seems that Apple gave us ordered sets for Core Data but forgot to upgrade its binding controllers. One year later after your question, the problem is still there.

Have a look at:

https://github.com/robertjpayne/DDOutlineView

Moral of the story. Be careful when using ordered relationships, try to do your own implementation until Apple fully implements that feature

Smollett answered 11/11, 2012 at 17:29 Comment(3)
It seems this is still an issue.Firewater
Btw. i just opend a bug report for this ... may this helps :)Firewater
Github link is broken. Proper link is here: github.com/neostoic/DDOutlineViewTurning

© 2022 - 2024 — McMap. All rights reserved.