Re: Inverse to-one relationships

2010-07-24 Thread Ramsey Lee Gurley
I tested it using a ERD2W edit relationship page subclass. I believe the code 
that sets up the edit relationship page uses addObjectToBothSide. 

On Jul 23, 2010, at 8:33 PM, Paul Hoadley wrote:

> On 23/07/2010, at 11:44 PM, Ramsey Gurley wrote:
> 
>> Nice trick Chuck (^_^) You are awesome!  And it seems so simple now, I 
>> wonder why I didn't try it sooner. This appears to work in both directions 
>> for me.
> 
> Are you using Wonder, Ramsey?  If so, does it work automatically when you set 
> the updateInverseRelationships property, or are you manually calling 
> addObjectToBothSidesOfRelationshipWithKey()?  This is the last tiny detail I 
> wouldn't mind ironing out.
> 
>> I must have looked through 10 years of archived list messages and never 
>> found an answer to this one.
> 
> You and me both!
> 
> 
> -- 
> Paul.
> 
> http://logicsquad.net/
> 
> 
> ___
> 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/rgurley%40mac.com
> 
> This email sent to rgur...@mac.com

 ___
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


Re: Inverse to-one relationships

2010-07-23 Thread Paul Hoadley
On 23/07/2010, at 11:44 PM, Ramsey Gurley wrote:

> Nice trick Chuck (^_^) You are awesome!  And it seems so simple now, I wonder 
> why I didn't try it sooner. This appears to work in both directions for me.

Are you using Wonder, Ramsey?  If so, does it work automatically when you set 
the updateInverseRelationships property, or are you manually calling 
addObjectToBothSidesOfRelationshipWithKey()?  This is the last tiny detail I 
wouldn't mind ironing out.

> I must have looked through 10 years of archived list messages and never found 
> an answer to this one.

You and me both!


-- 
Paul.

http://logicsquad.net/


 ___
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


Re: Inverse to-one relationships

2010-07-23 Thread Chuck Hill

On Jul 23, 2010, at 8:29 AM, David Avendasora wrote:

> 
> On Jul 23, 2010, at 10:22 AM, Chuck Hill wrote:
> 
>> It is not me, it is EOF that is awesome.  I just remember the specifics.  ;-)
> 
> That makes you the WOman then, right?

Sounds like a WOWODC shirt in the making there...


-- 
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







 ___
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


Re: Inverse to-one relationships

2010-07-23 Thread David Avendasora

On Jul 23, 2010, at 10:22 AM, Chuck Hill wrote:

> It is not me, it is EOF that is awesome.  I just remember the specifics.  ;-)

That makes you the WOman then, right?

Dave ___
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


Re: Inverse to-one relationships

2010-07-23 Thread Chuck Hill
On Jul 23, 2010, at 7:14 AM, Ramsey Gurley wrote:
> On Jul 22, 2010, at 9:17 PM, Paul Hoadley wrote:
>> On 23/07/2010, at 10:20 AM, Chuck Hill wrote:
>> 
 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?
>> 
>> Yes.
>> 
 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.
>> 
>> OK.  I'll work around it.
>> 
 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.
>> 
>> Ah, OK.  Well, this has all ended quite nicely.  Thanks all.
>> 
>> 
>> -- 
>> Paul.
>> 
>> http://logicsquad.net/
>> 
> 
> Nice trick Chuck (^_^) You are awesome!  

It is not me, it is EOF that is awesome.  I just remember the specifics.  ;-)


Chuck


> And it seems so simple now, I wonder why I didn't try it sooner. This appears 
> to work in both directions for me. I must have looked through 10 years of 
> archived list messages and never found an answer to this one.
> 
> Anyway, thank you again Chuck and thank you too Paul for asking the question 
> one more time.
> 
> Ramsey
> 
> 
> ___
> 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/chill%40global-village.net
> 
> This email sent to ch...@global-village.net

-- 
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









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

Re: Inverse to-one relationships

2010-07-23 Thread Ramsey Gurley


On Jul 22, 2010, at 9:17 PM, Paul Hoadley wrote:


On 23/07/2010, at 10:20 AM, Chuck Hill wrote:

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?


Yes.

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.


OK.  I'll work around it.

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.


Ah, OK.  Well, this has all ended quite nicely.  Thanks all.


--
Paul.

http://logicsquad.net/



Nice trick Chuck (^_^) You are awesome!  And it seems so simple now, I  
wonder why I didn't try it sooner. This appears to work in both  
directions for me. I must have looked through 10 years of archived  
list messages and never found an answer to this one.


Anyway, thank you again Chuck and thank you too Paul for asking the  
question one more time.


Ramsey


___
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


Re: Inverse to-one relationships

2010-07-22 Thread Paul Hoadley
On 23/07/2010, at 10:20 AM, Chuck Hill wrote:

>> 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?

Yes.

>> 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.

OK.  I'll work around it.

>> 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.

Ah, OK.  Well, this has all ended quite nicely.  Thanks all.


-- 
Paul.

http://logicsquad.net/


 ___
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


Re: Inverse to-one relationships

2010-07-22 Thread Chuck Hill
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.
>> 
>> 
>> public String inverseForRelationshipKey(String relationshipKey){
>>if (relationshipKey.equals("creditCard"))
>>return( "member" );
>>else
>>return( super.inverseForRelationshipKey(relationshipKey) );
>> }
>> 
> 
> 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









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

Re: Inverse to-one relationships

2010-07-22 Thread Paul Hoadley
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.
> 
> 
> public String inverseForRelationshipKey(String relationshipKey){
> if (relationshipKey.equals("creditCard"))
> return( "member" );
> else
> return( super.inverseForRelationshipKey(relationshipKey) );
> }
> 

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?  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.)  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?

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!)


-- 
Paul.

http://logicsquad.net/


 ___
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


Re: Inverse to-one relationships

2010-07-22 Thread Chuck Hill

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

> On 23/07/2010, at 7:42 AM, Chuck Hill wrote:
> 
 How are you modeling these relationships?
>>> 
>>> Originally, just this: a mandatory, to-one relationship from A to B.  
>>> Consider it to be a parent (B) with optional child (A).  Every child has a 
>>> parent (hence the current mandatory to-one from A to B), and every parent 
>>> has zero or one child.  So I've tacked on an optional to-one relationship 
>>> from B to A to model the latter.  I take it there's no way to convince EOF 
>>> that these relationships are inverses, and get the convenience of updating 
>>> both sides of the relationship at the same time.
>> 
>> Where are the FKs?  B hold's A's PK as an FK?
> 
> Yes, and vice versa.  Only difference is that B to A is optional (parent can 
> have zero children), A to B is mandatory (child must have a parent).
> 
>> They both have the same PK?
> 
> No.  (Would this help?)


It would make it worse, I just wanted to understand the situation.


-- 
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









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

Re: Inverse to-one relationships

2010-07-22 Thread Chuck Hill

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.

 
 public String inverseForRelationshipKey(String relationshipKey){
 if (relationshipKey.equals("creditCard"))
 return( "member" );
 else
 return( super.inverseForRelationshipKey(relationshipKey) );
 }
 


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









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

Re: Inverse to-one relationships

2010-07-22 Thread Paul Hoadley
On 23/07/2010, at 7:42 AM, Chuck Hill wrote:

>>> How are you modeling these relationships?
>> 
>> Originally, just this: a mandatory, to-one relationship from A to B.  
>> Consider it to be a parent (B) with optional child (A).  Every child has a 
>> parent (hence the current mandatory to-one from A to B), and every parent 
>> has zero or one child.  So I've tacked on an optional to-one relationship 
>> from B to A to model the latter.  I take it there's no way to convince EOF 
>> that these relationships are inverses, and get the convenience of updating 
>> both sides of the relationship at the same time.
> 
> Where are the FKs?  B hold's A's PK as an FK?

Yes, and vice versa.  Only difference is that B to A is optional (parent can 
have zero children), A to B is mandatory (child must have a parent).

> They both have the same PK?

No.  (Would this help?)


-- 
Paul.

http://logicsquad.net/


 ___
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


Re: Inverse to-one relationships

2010-07-22 Thread Paul Hoadley
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.


-- 
Paul.

http://logicsquad.net/


 ___
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


Re: Inverse to-one relationships

2010-07-22 Thread Chuck Hill

On Jul 22, 2010, at 2:49 PM, Paul Hoadley wrote:

> On 23/07/2010, at 12:09 AM, Chuck Hill wrote:
> 
>>> I know this topic comes up on the list from time to time, but I just need a 
>>> quick sanity check.
>> 
>> Nope, not sane.  :-)
> 
> Well spotted.  Now on with this:
> 
>>> I have two entities, A and B.  For every A, there is a corresponding B.  
>>> For some subset of all Bs, each has a corresponding A.  Currently I have 
>>> modelled this with a single relationship from A to B, so that's a mandatory 
>>> to-one relationship.  (Alternatively, I could have modelled it with an 
>>> optional to-one relationship from B to A.)
>> 
>> How are you modeling these relationships?
> 
> Originally, just this: a mandatory, to-one relationship from A to B.  
> Consider it to be a parent (B) with optional child (A).  Every child has a 
> parent (hence the current mandatory to-one from A to B), and every parent has 
> zero or one child.  So I've tacked on an optional to-one relationship from B 
> to A to model the latter.  I take it there's no way to convince EOF that 
> these relationships are inverses, and get the convenience of updating both 
> sides of the relationship at the same time.

Where are the FKs?  B hold's A's PK as an FK?   They both have the same PK?

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









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

Re: Inverse to-one relationships

2010-07-22 Thread Chuck Hill

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   
A.FKB == B.PK   


I think...



-- 
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









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

Re: Inverse to-one relationships

2010-07-22 Thread Paul Hoadley
Hi David,

On 23/07/2010, at 6:33 AM, David Avendasora wrote:

> I'm not 100% clear on how this is modeled.
> 
> 1) Does the A.b() relationship propagate PKs?

No.

> 2) Are you saying that the A.b().a() may be null?

No, never.  A.b().a() would always give A.

> In other words, are you saying A.fetchAllAs().valueForKey(B_KEY) may not 
> return an Array with the same objects that B.fetchAllBs(ec, B.A.isNotNull()) ?

No, I'm not saying that.  Those two expressions would return the same objects.

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.


-- 
Paul.

http://logicsquad.net/


 ___
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


Re: Inverse to-one relationships

2010-07-22 Thread Paul Hoadley
On 23/07/2010, at 12:09 AM, Chuck Hill wrote:

>> I know this topic comes up on the list from time to time, but I just need a 
>> quick sanity check.
> 
> Nope, not sane.  :-)

Well spotted.  Now on with this:

>> I have two entities, A and B.  For every A, there is a corresponding B.  For 
>> some subset of all Bs, each has a corresponding A.  Currently I have 
>> modelled this with a single relationship from A to B, so that's a mandatory 
>> to-one relationship.  (Alternatively, I could have modelled it with an 
>> optional to-one relationship from B to A.)
> 
> How are you modeling these relationships?

Originally, just this: a mandatory, to-one relationship from A to B.  Consider 
it to be a parent (B) with optional child (A).  Every child has a parent (hence 
the current mandatory to-one from A to B), and every parent has zero or one 
child.  So I've tacked on an optional to-one relationship from B to A to model 
the latter.  I take it there's no way to convince EOF that these relationships 
are inverses, and get the convenience of updating both sides of the 
relationship at the same time.


-- 
Paul.

http://logicsquad.net/


 ___
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

Re: Inverse to-one relationships

2010-07-22 Thread Paul Hoadley
On 22/07/2010, at 11:42 PM, Ramsey Gurley wrote:

> One-to-optional-one relationship...  Not doable as far as I know.  In another 
> discussion on the topic, Chuck Hill suggested:
> 
>> 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
> 
> Great idea. I gave that a shot, but it didn't work.
> 
> Beyond that, I've considered modeling a typical one-to-many, applying a 
> unique constraint to the FK, creating a method to get/set the relationship, 
> and then register a custom EOClassDescription to replace the reported toMany 
> with my getter/setter toOne.  I haven't tried the custom EOClassDescription 
> bit yet though.

Thanks Ramsey.  That's pretty much what I thought.


-- 
Paul.

http://logicsquad.net/

 ___
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


Re: Inverse to-one relationships

2010-07-22 Thread David Avendasora
Hi Paul,

I'm not 100% clear on how this is modeled.

1) Does the A.b() relationship propagate PKs?

2) Are you saying that the A.b().a() may be null? In other words, are you 
saying A.fetchAllAs().valueForKey(B_KEY) may not return an Array with the same 
objects that B.fetchAllBs(ec, B.A.isNotNull()) ?

Dave

On Jul 22, 2010, at 8:00 AM, Paul Hoadley wrote:

> Hello,
> 
> I know this topic comes up on the list from time to time, but I just need a 
> quick sanity check.
> 
> I have two entities, A and B.  For every A, there is a corresponding B.  For 
> some subset of all Bs, each has a corresponding A.  Currently I have modelled 
> this with a single relationship from A to B, so that's a mandatory to-one 
> relationship.  (Alternatively, I could have modelled it with an optional 
> to-one relationship from B to A.)
> 
> At different times, I need to traverse this relationship in both directions.  
> For any A, A.b() will give me the related B.  But for the reverse direction, 
> say I have a B and I want its A (if it has one), I have a custom method B.a() 
> which does a fetch for the A such that A.b() is the B of interest.  
> Sometimes, though, I just want to know if there is an A for a particular B, 
> or whether it's null, and in this setting, the fetch is expensive.
> 
> Here's where I need the sanity check: is there a way, given the constraints 
> above, to model an inverse to-one relationship from B to A such that it 
> appears as the inverse to EOF?  That is, such that calling, say, 
> A.addObjectToBothSidesOfRelationshipWithKey(B, "b") does both A.setB(B) and 
> B.setA(A)?  I'm assuming there's not, as I certainly can't beat the model 
> into doing it.  I can work around it by doing the right thing at creation 
> time for every A, I just wanted to know if I was missing something where EOF 
> (or Wonder) would handle this automagically.
> 
> 
> -- 
> Paul.
> 
> http://logicsquad.net/
> 
> 
> ___
> 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/webobjects%40avendasora.com
> 
> This email sent to webobje...@avendasora.com
> 
> 

 ___
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


Re: Inverse to-one relationships

2010-07-22 Thread Chuck Hill

On Jul 22, 2010, at 5:00 AM, Paul Hoadley wrote:

> Hello,
> 
> I know this topic comes up on the list from time to time, but I just need a 
> quick sanity check.

Nope, not sane.  :-)


> I have two entities, A and B.  For every A, there is a corresponding B.  For 
> some subset of all Bs, each has a corresponding A.  Currently I have modelled 
> this with a single relationship from A to B, so that's a mandatory to-one 
> relationship.  (Alternatively, I could have modelled it with an optional 
> to-one relationship from B to A.)
> 
> At different times, I need to traverse this relationship in both directions.  
> For any A, A.b() will give me the related B.  But for the reverse direction, 
> say I have a B and I want its A (if it has one), I have a custom method B.a() 
> which does a fetch for the A such that A.b() is the B of interest.  
> Sometimes, though, I just want to know if there is an A for a particular B, 
> or whether it's null, and in this setting, the fetch is expensive.
> 
> Here's where I need the sanity check: is there a way, given the constraints 
> above, to model an inverse to-one relationship from B to A such that it 
> appears as the inverse to EOF?  That is, such that calling, say, 
> A.addObjectToBothSidesOfRelationshipWithKey(B, "b") does both A.setB(B) and 
> B.setA(A)?  I'm assuming there's not, as I certainly can't beat the model 
> into doing it.  I can work around it by doing the right thing at creation 
> time for every A, I just wanted to know if I was missing something where EOF 
> (or Wonder) would handle this automagically.


How are you modeling these relationships?

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









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

Re: Inverse to-one relationships

2010-07-22 Thread Ramsey Gurley
One-to-optional-one relationship...  Not doable as far as I know.  In  
another discussion on the topic, Chuck Hill suggested:


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


Great idea. I gave that a shot, but it didn't work.

Beyond that, I've considered modeling a typical one-to-many, applying  
a unique constraint to the FK, creating a method to get/set the  
relationship, and then register a custom EOClassDescription to replace  
the reported toMany with my getter/setter toOne.  I haven't tried the  
custom EOClassDescription bit yet though.


Ramsey

On Jul 22, 2010, at 8:00 AM, Paul Hoadley wrote:


Hello,

I know this topic comes up on the list from time to time, but I just  
need a quick sanity check.


I have two entities, A and B.  For every A, there is a corresponding  
B.  For some subset of all Bs, each has a corresponding A.   
Currently I have modelled this with a single relationship from A to  
B, so that's a mandatory to-one relationship.  (Alternatively, I  
could have modelled it with an optional to-one relationship from B  
to A.)


At different times, I need to traverse this relationship in both  
directions.  For any A, A.b() will give me the related B.  But for  
the reverse direction, say I have a B and I want its A (if it has  
one), I have a custom method B.a() which does a fetch for the A such  
that A.b() is the B of interest.  Sometimes, though, I just want to  
know if there is an A for a particular B, or whether it's null, and  
in this setting, the fetch is expensive.


Here's where I need the sanity check: is there a way, given the  
constraints above, to model an inverse to-one relationship from B to  
A such that it appears as the inverse to EOF?  That is, such that  
calling, say, A.addObjectToBothSidesOfRelationshipWithKey(B, "b")  
does both A.setB(B) and B.setA(A)?  I'm assuming there's not, as I  
certainly can't beat the model into doing it.  I can work around it  
by doing the right thing at creation time for every A, I just wanted  
to know if I was missing something where EOF (or Wonder) would  
handle this automagically.



--
Paul.

http://logicsquad.net/



___
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


Inverse to-one relationships

2010-07-22 Thread Paul Hoadley
Hello,

I know this topic comes up on the list from time to time, but I just need a 
quick sanity check.

I have two entities, A and B.  For every A, there is a corresponding B.  For 
some subset of all Bs, each has a corresponding A.  Currently I have modelled 
this with a single relationship from A to B, so that's a mandatory to-one 
relationship.  (Alternatively, I could have modelled it with an optional to-one 
relationship from B to A.)

At different times, I need to traverse this relationship in both directions.  
For any A, A.b() will give me the related B.  But for the reverse direction, 
say I have a B and I want its A (if it has one), I have a custom method B.a() 
which does a fetch for the A such that A.b() is the B of interest.  Sometimes, 
though, I just want to know if there is an A for a particular B, or whether 
it's null, and in this setting, the fetch is expensive.

Here's where I need the sanity check: is there a way, given the constraints 
above, to model an inverse to-one relationship from B to A such that it appears 
as the inverse to EOF?  That is, such that calling, say, 
A.addObjectToBothSidesOfRelationshipWithKey(B, "b") does both A.setB(B) and 
B.setA(A)?  I'm assuming there's not, as I certainly can't beat the model into 
doing it.  I can work around it by doing the right thing at creation time for 
every A, I just wanted to know if I was missing something where EOF (or Wonder) 
would handle this automagically.


-- 
Paul.

http://logicsquad.net/


 ___
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