On Jul 22, 2010, at 3:37 PM, Paul Hoadley wrote:

> On 23/07/2010, at 7:32 AM, Chuck Hill wrote:
> 
>> On Jul 22, 2010, at 2:56 PM, Paul Hoadley wrote:
>> 
>>> Sorry, I should have tried to be clearer.  Basically, I've got a parent 
>>> object B (which will always be created first).  At some point, B may obtain 
>>> at most one child A, but it doesn't necessarily.  So every B has zero or 
>>> one child As.  Every A has exactly one parent B.
>>> 
>>> Currently I have a mandatory to-one relationship from A to B (so A knows 
>>> its parent directly).  To avoid some fetching, I have added an optional 
>>> to-one relationship from B to A, so B knows its child if it has one.  I 
>>> assume there's no way to make these relationships inverses from EOF's 
>>> perspective, and that I will just need to be careful about always setting 
>>> the B to A relationship on creation of an A.
>> 
>> How did you model this?  B hold's the PK of A as a FK?  They each need a FK 
>> for the other, I think.  Your relationships should be
>> 
>> B.FKA == A.PK   [1]
>> A.FKB == B.PK   [2]
>> 
>> I think...
> 
> Yeah, that's exactly what I've done.  And [1] is optional (because not every 
> B (parent) has an A (child)), and [2] is mandatory (because every A (child) 
> has a B (parent)).  But AFAICS, they're not being recognised as inverse 
> relationships.  Which is fine, because that's what my archive searching lead 
> me to expect, but I wanted to, uh, go over it one more time.


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>


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      (Webobjects-dev@lists.apple.com)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to