Re: Newbie vs Many-To-Many (0 win-1 win)
Re: Newbie vs Many-To-Many (0 win-1 win)
- Subject: Re: Newbie vs Many-To-Many (0 win-1 win)
- From: Art Isbell <email@hidden>
- Date: Sat, 1 Mar 2003 11:16:50 -1000
On Friday, February 28, 2003, at 02:45 PM, Riccardo De Menna wrote:
I have to entities, Clients and Contacts. Contacts has a nice
"Profile" component with a WOBrowser that lists the Clients to which
you can connect the record. The submission of this page immediately
saves the editing context. It work's fine and data is correctly added
to db's but, when I switch to check the "Client" profile (where I
should see the newly added Contact), the record is not there.
If I quit and restart the application though, the changes are
reflected and everything is ok. I assume the problem has to do with
the fact that I've missed the part where I also update the
Client.contacts array in memory (even though the db's are already
populated with correct data). But I'm confused on what should I do.
Should I use the addObjectToPropertyWithKey or
addObjectToBothSidesOfRelationshipWithKey when saving the editing
context? Even if I'm just updating a record and not adding? Or should
I simply refetch everything so that the new configuration is loaded?
You should always use addObjectToBothSidesOfRelationshipWithKey()
which works regardless of whether the relationship is to-one, to-many,
flattened, or has no inverse relationship (i.e., no "other side").
addObjectToBothSidesOfRelationshipWithKey() invokes
addObjectToPropertyWithKey() for the relationship whose key is
specified and its inverse relationship, if it exists.
If you used addObjectToPropertyWithKey(), I think you've analyzed the
results correctly; the inverse relationship, Client.contacts, wasn't
updated in memory when you updated Contact.clients.
Art
http://homepage.mac.com/aisbell/
_______________________________________________
webobjects-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/webobjects-dev
Do not post admin requests to the list. They will be ignored.