Core Data and ordered to-many relations
Is there a way to represent an ordered to-many relation? For example,
suppose you have an entity, Person, related to itself (one-to-many).
Now suppose Alice is related to Carol and Dave, and Bob is related to
Dave and Carol, in the order prescribed.
Is there a way to model that using a relationship, or would I have to
use an alternate structure?
If there's only two relatives, as in your example, use two to-one
If there's an indeterminate number, you can add an intermediate
"joiner" entity, as explained here:
The above joins between two different entities, so you'll modify it to
join the same entity. All data modelling situations are a little
Didn't the OP want the relatives joined in a specific order (or, at
least, be able to retrieve them in a specific order)?
"in the order prescribed."
To do that, joins alone won't satisfy his query (Core Data structures
are not guaranteed to return in any order). As I read them, his
options were "joins only" or "some other structure."
In the OP's case, he'd need to have (as one possible solution) both a
relationship entity and an order attribute of some kind in that entity
to answer his request (the order attribute would also be as per dox).
This would be the "other structure," at least from my perspective.
Peace, Love, and Light,
/s/ Jon C. Munson II
Quoting Jerry Krinock <jerry...>:
> If there's only two relatives, as in your example, use two to-one
> If there's an indeterminate number, you can add an intermediate
> "joiner" entity, as explained here:
> The above joins between two different entities, so you'll modify it to
> join the same entity. All data modelling situations are a little
On May 25, 2009, at 12:15 AM, Kelvin Chung wrote:
> Is there a way to represent an ordered to-many relation?
It sounds like you need Brain Webster's BWOrderedManagedObject: http://www.fatcatsoftware.com/blog/2008/per-object-ordered-relationships-us
It adds mutableOrderedValueForKey: (and some other useful methods) to
NSManagedObject, allowing to-many relationships to be stored with a
specified order. I've been using it in one of my projects and it works
like a charm.