Re: Inverse to-one relationships
Re: Inverse to-one relationships
- Subject: Re: Inverse to-one relationships
- From: Chuck Hill <email@hidden>
- Date: Thu, 22 Jul 2010 17:50:15 -0700
On Jul 22, 2010, at 5:22 PM, Paul Hoadley wrote:
> On 23/07/2010, at 8:25 AM, Chuck Hill wrote:
>
>> OK, now that we are all on the same page :-), see the JavaDocs for EOEnterpriseObject:
>>
>> inverseForRelationshipKey
>>
>> String inverseForRelationshipKey(String relationshipKey)
>> Returns the name of the relationship pointing back to the receiver's class or entity from that named by relationshipKey, or null if there isn't one. With the access layer's EOEntity and EORelationship classes, for example, reciprocality is determined by the join attributes of the two EORelationships. EOCustomObject's implementation simply sends an inverseForRelationshipKey message to the receiver's EOClassDescription.
>> You might override this method for reciprocal relationships that aren't defined using the same join attributes. For example, if a Member object has a relationship to CreditCard based on the card number, but a CreditCard has a relationship to Member based on the Member's primary key, both classes need to override this method. This is how Member might implement it.
>>
>> <blockquote>
>> public String inverseForRelationshipKey(String relationshipKey){
>> if (relationshipKey.equals("creditCard"))
>> return( "member" );
>> else
>> return( super.inverseForRelationshipKey(relationshipKey) );
>> }
>> </blockquote>
>
> Outstanding, thanks Chuck. Would you believe I got as far as the Javadocs for EOCustomObject.inverseForRelationshipKey(), and convinced myself that it didn't look like the sort of thing I should be overriding?
Yes, I would. :-)
> If only I had clicked one more hyperlink...
>
> In any case, that works. Here are some follow-up questions:
>
> 1. It only works when I call a.addObjectToBothSidesOfRelationshipWithKey(b, "b"). (Don't get me wrong—that's great, an enormous improvement on what I was doing 5 minutes ago.)
Did you add versions of this method to both entities?
> I've got Wonder's updateInverseRelationships property set true, but it doesn't seem to be automatically updating this relationship. (It is working as designed on others.) In fact, inverseForRelationshipKey() isn't even being called, unless I manually call addObjectToBothSidesOfRelationshipWithKey(). Is this expected?
I don't know.
> 2. Slightly more academic: why did everything I had read previously make me think this wouldn't work? I had also read that post from Chuck quoted in this thread by Ramsey:
>
>> You could model it as a right-outer join and optional, but I think that EOF is still going to have a hissy fit when it does not find the row. Worth a try and a good bug to log with Apple if it does not work.
>
>
> Chuck, were you talking about something else there? (Presumably the answer is: I was mis-reading everything, and I didn't describe the problem clearly enough for Ramsey!)
I am pretty sure that was referring to a PK - PK relationship when the PK is propagated from the parent to the child.
Chuck
--
Chuck Hill Senior Consultant / VP Development
Practical WebObjects - for developers who want to increase their overall knowledge of WebObjects or who are trying to solve specific problems.
http://www.global-village.net/products/practical_webobjects
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
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