Re: why does selecting a parent not make me it's child?
Re: why does selecting a parent not make me it's child?
- Subject: Re: why does selecting a parent not make me it's child?
- From: Denis Stanton <email@hidden>
- Date: Tue, 15 Jul 2003 11:17:11 +1200
Hi Chuck
Thanks for your help
On Tuesday, July 15, 2003, at 03:00 AM, Chuck Hill wrote:
> This is because your code is only setting one half of the relationship
> and
> not calling addObjectToBothSideOfRelationshipWithKey.
I'm not very clear on this. I have read the definition of
addObjectToBothSideOfRelationshipWithKey and it is clearly addressing
the issue, but I'm not sure where to use it. In my small example the
pop up takes care of setting the child.parent relationship.
Is it simply a matter of changing the child class and replacing
public void setParent(Parent value) {
takeStoredValueForKey(value, "parent");
}
with
public void setParent(Parent value) {
addObjectToBothSidesOfRelationshipWithKey(value, "parent");
}
This was not a success as I got sigbus 10 error which is sometimes a
sign of "unwanted recursion" :-) There must be more to it
> The WOToOneRelationship might be useful to you here.
You lost me. Parent->child is a one-to-many relationship, so going the
other way the relationship inspector shows "to one" is that what you
are referring to?
> Otherwise you can:
> 1. Roll your own version of WOToOneRelationship that does what you
> want.
> 2. Add cover methods in the page to do it
Sounds wasteful. The page doesn't need my code to change the child->
parent because the pop up does this half of the job. I'm not sure what
method I should be covering.
> 3. Add cover methods in the object to do it (e.g.
> currentParent()/setCurrentParent() )
That sounds more promising.
The generated class includes:
public class Child extends EOGenericRecord {
public Child() {
super();
}
public void setParent(Parent value) {
takeStoredValueForKey(value, "parent");
}
Should I extend this to something like the following?
public void setParent(Parent value) {
Parent oldParent = this.parent();
oldParent.removeFromHires(this);
value.addToHires(this);
takeStoredValueForKey(value, "parent");
}
Of course, rather that ask you this I can ask the compiler. ....
I'll be back ....
<pause>
I've just tried the code above and it appears to work. Now I'm
wondering why WO doesn't generate this code by itself?
The main thing is it works and I'm back in business. Much thanks for
your advice. Now I just have to hunt around for any other setParent()
methods.
Denis
_______________________________________________
webobjects-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/webobjects-dev
Do not post admin requests to the list. They will be ignored.