One-to-One Relationship
One-to-One Relationship
- Subject: One-to-One Relationship
- From: Louis Demers <email@hidden>
- Date: Wed, 22 Mar 2006 01:06:31 -0500
Title: One-to-One Relationship
Hi,
-----------
Background:
I have two objects setup tied by a bidirectional one-to-one
optional relationships. both classes have acessors for the
relationships in their classe.
TelehoneLine.java contains
public class TelephoneLine extends
EOGenericRecord {
...
public Contact employee() {
return (Contact)storedValueForKey("employee");
}
public void setEmployee(Contact value) {
takeStoredValueForKey(value,
"employee");
}
...
}
Contact.java contains
public class Contact extends
EOGenericRecord {
...
public TelephoneLine telephoneLine() {
return (TelephoneLine)storedValueForKey("telephoneLine");
}
public void setTelephoneLine(TelephoneLine value) {
takeStoredValueForKey(value,
"telephoneLine");
}
...
}
Both one-to-one relationships (employee and
telephoneLine) are defined
optional, nullify, DO NOT own destinations. and their foreign
keys allow zeros.
--------
Problem:
When I use
"addObjectToBothSidesOfRelationshipWithKey"
aTelephoneLine.addObjectToBothSidesOfRelationshipWithKey(selectedEmployee,"employee");
only half of the relationships get updated. I crafted the
following code that does update both sides
-----------
Workaround:
if
(aTelephoneLine.employee() != null ){
aTelephoneLine.employee().setTelephoneLine(null);
}
aTelephoneLine.setEmployee(selectedEmployee);
if
(selectedEmployee != null ){
selectedEmployee.setTelephoneLine(aTelephoneLine);
}
but I don't undestand why
"addObjectToBothSidesOfRelationshipWithKey" doesnt' work and
suspect I screwed up somewhere.
--
Louis Demers ing.
2447 Bellevue
St-Romuald, Quebec
Canada G6W 2T8
418 839-9266 (res.)
418 953-6204 (cell.)
email@hidden
email@hidden
_______________________________________________
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