• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: One-to-One Relationship
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: One-to-One Relationship


  • Subject: Re: One-to-One Relationship
  • From: Christian Pekeler <email@hidden>
  • Date: Wed, 22 Mar 2006 09:50:09 -0700

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@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: One-to-One Relationship
      • From: Christian Brunschen <email@hidden>
References: 
 >One-to-One Relationship (From: Louis Demers <email@hidden>)

  • Prev by Date: Re: Deployment error not in Dev?
  • Next by Date: Re: One-to-One Relationship
  • Previous by thread: Re: One-to-One Relationship
  • Next by thread: Re: One-to-One Relationship
  • Index(es):
    • Date
    • Thread