I have two objects setup tied by a bidirectional one-to-one optional relationships.
Problem:
When I use "addObjectToBothSidesOfRelationshipWithKey"
only half of the relationships get updated. I crafted the following code that does update both sides I don't undestand why "addObjectToBothSidesOfRelationshipWithKey" doesnt' work and suspect I screwed up somewhere.

EOCustomObject.addObjectToBothSidesOfRelationshipWithKey(obj, key) is only taking care of both sides if it can find the reciprocal (also called inverse or back-) relationship to the relationship you've specified as key. To do that, addObjectToBothSidesOfRelationshipWithKey is using EORelationship.inverseRelationship() which searches the destination entity for a relationship that points back to our entity using a reciprocal join.

For example, if we have a relationship from A to B using the join [A.a_id, B.a_id] (in other words, B has a foreign key a_id for a to- many relationship from A to B), addObjectToBothSidesOfRelationshipWithKey is looking for a back- relationship with the join [B.a_id, A.a_id] (in other words, we're looking for a to-one relationship from B to A using the same keys/ attributes/columns).

In your case with the optional one-to-one relationship, the joins are [A.b_id, B.b_id] and [B.a_id, A.a_id] which are not reciprocal, i.e. EORelationship.inverseRelationship() can't identify these joins as being related to each other. You didn't "screw up" - this is just a case where you need to explicitly maintain both sides of the relationship. One way to do that would be to overwrite addObjectToBothSidesOfRelationshipWithKey in A and B to check if the key is for a one-to-one relationship and then specifically deal with it.


Christian





_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      ([email protected])
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to