Re: (newbie)saving many-to-many relationship
Re: (newbie)saving many-to-many relationship
- Subject: Re: (newbie)saving many-to-many relationship
- From: Nathan Dumar <email@hidden>
- Date: Sun, 12 Sep 2004 16:15:38 -0400
On Sep 12, 2004, at 3:09 AM, Tom Jones wrote:
I have to entities requirements and tasks, a task can fulfiull several
requirements, a requirement can be fulfilled by several tasks. A user
creates the relationship between the two by choosing requirements from
a WOBrowser, with multiple select enabled. Do I need to call
addObjectToBothSidesOfRelationshipWithKey for each requirement
selected, or is it sufficient to just call it once and pass the
entire array of requirements.
Tom,
The API for EORelationshipManipulation says that it can only use an
enterprise object as an argument (not an array of many objects), so
you'll have to do addObjectToBothSidesOfRelationshipWithKey() for each
item, instead of once for the entire array. This means you'll have to
set up a loop and execute the above command for each item in the array.
For example:
int z = 0;
while ( selectedObjects.count() != z ) {
firstObject.addObjectToBothSidesOfRelationshipWithKey(selectedObject.obj
ectAtIndex(z), relationshipName);
++z;
}
If the former is the correct way, how does one update the task, do you
first remove all of the requirements and then add the selected items
to both sides?
That depends on what you want for your final result. If you want only
the objects that were selected in the WOBrowser to be on the other side
of the relationship, then you have to first remove all the other
objects before addObjectToBothSides...(). If you want to add the
objects that were selected in the WOBrowser to the items already in the
relationship, then you would not first remove the other objects.
addObjectToBothSidesOfRelationshipWithKey() does not first remove other
objects; it only adds more objects to the relationship.
Take care,
Nathan
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden