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: Chuck Hill <email@hidden>
- Date: Tue, 15 Jul 2003 14:15:27 -0700
- Organization: Global Village Consulting, Inc.
Hi Denis,
Denis Stanton wrote:
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
Yeah, don't do it that way. :-) That is why my third proposal was
"Add cover methods in the object to do it (e.g.
currentParent()/setCurrentParent() )"
addObjectToBothSidesOfRelationshipWithKey will end up calling
setParent. That is where the recursion came from. Try this instead:
public Parent currentParent() {
return parent();
}
public void setCurrentParent(Parent value) {
addObjectToBothSidesOfRelationshipWithKey(value, "parent");
}
Then use currentParent for the bindings in place of parent.
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?
Maybe I misunderstood. There is also a WOToManyRelationship
component. Both, I think, use
addObjectToBothSidesOfRelationshipWithKey(value, "parent") instead of
setParent() to make the change.
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.
You could add parent/setParent methods on the page and implement them
similarly to what I put above.
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.
I would not do this, this is what
addObjectToBothSidesOfRelationshipWithKey does, but not as flexibly.
What I really meant was the currentParent/setCurrentParent pair above.
Chuck
--
Chuck Hill email@hidden
Global Village Consulting Inc. http://www.global-village.net
Progress is the mother of all problems.
- G. K. Chesterton
_______________________________________________
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.