Re: many-to-many relationships and object design
Re: many-to-many relationships and object design
- Subject: Re: many-to-many relationships and object design
- From: Todd Ransom <email@hidden>
- Date: Thu, 17 Jun 2004 23:01:08 -0600
Don't I run a risk of the data becoming out os sync if I do this?
For example, I add an actor object to the actors array in a scene
object. Later, I update a property of the actor (actors have a "notes"
property where I can take notes about them). Do I have two different
actor objects, or do I have two references to the same actor? And what
about when I serialize/unserialize using
encodeWithCoder:/initWithCoder: ? I don't see how my scene object
could get a reference to an existing actor object during
unserialization. That's why I think I need a method for resolving IDs
to objects, so I can serialize the IDs and unserialize as objects.
thanks for your help,
TR
On Jun 17, 2004, at 9:28 PM, mmalcolm crawford wrote:
It's reasonable to model the many-to-many directly as arrays (although
you might instead use sets):
Actor <<->> Scene
@interface Actor : NSObject
{
NSMutableArray *scenes;
}
@interface Scene : NSObject
{
NSMutableArray *actors;
}
The main conceptual hurdle comes in manipulating the relationship. In
the RDBMS relationships are "implicit," so to find out what actors are
in a given scene you do a join. To manipulate relationships you
"simply" either add or remove records from the join table. In the
object world as suggested above relationships are "explicit,"
represented by arrays. Therefore to add an actor to a scene you
cannot simply add the actor to the scene's 'actors' array, to maintain
consistency of your object graph you must also ensure that the scene
is added to the actor's 'scenes' array. If you cut an actor from the
scene, you must ensure that both actor and scene are aware of the
deletion. It's not that difficult to implement, but takes a little
care and thinking about.
For more about object-relational mapping, you might care to browse
through
<http://developer.apple.com/documentation/WebObjects/
Enterprise_Objects/index.html>
mmalc
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.