Re: Why can't I get <addObjectToBothSidesOfRelationshipWithKey> right?
Re: Why can't I get <addObjectToBothSidesOfRelationshipWithKey> right?
- Subject: Re: Why can't I get <addObjectToBothSidesOfRelationshipWithKey> right?
- From: Arturo PĂ©rez <email@hidden>
- Date: Mon, 14 Mar 2005 19:26:39 -0500
When you set a relationship to be "Owns Destination" EOF automatically
creates one for you. So, you already have a Task. When you make a new
one and add it you end up with one floating around uninitialized.
Your code should be
In the WOComponent
EOClassDescription cd =
EOClassDescription.classDescriptionForEntityName( "Event" );
Event event = (Event)cd.createInstanceWithEditingContext( ec, null );
ec.insertObject( event );
...
Task t = event.task();
// set up task properly.
ec.saveChanges();
-arturo
On Mar 14, 2005, at 6:53 PM, Baiss Eric Magnusson wrote:
I have an Event record which wants to have a Task record, it is to be
a one-to-one relationship.
I set the relationship delete rules from the Event record to the Task
record to be:
Cascade
Owns Destination
Propagate
From the Task record to the Event record I set relationship delete
rules to be:
Nullify
In the model, I define the primary key for the Task record to be
<eventID>, which is the same name as the primary key of the Event
record. I don't set the primary key attribute for the Task table in
FB.
At <doAddEvent> time, (both records are created at once):
In Event, which overrides EOGenericRecord
public Task toTask() {
return (Task)storedValueForKey("toTask");
}
In the WOComponent
EOClassDescription cd =
EOClassDescription.classDescriptionForEntityName( "Event" );
Event event = (Event)cd.createInstanceWithEditingContext( ec, null );
ec.insertObject( event );
...
EOClassDescription cd =
EOClassDescription.classDescriptionForEntityName( "Task" );
Task newTask = (Task)cd.createInstanceWithEditingContext( ec, null );
ec.insertObject( newTask );
...
event.addObjectToBothSidesOfRelationshipWithKey( newTask, "toTask");
ec.saveChanges();
Which causes:
WOComponentRequestHandler>: Exception occurred while handling request:
NSForwardException [java.lang.IllegalArgumentException] Attempt to
insert null object into an NSMutableDictionary:
<doAddEvent> failed trying to enter a new Event
In FB, I define in Task the foreign key
foreign key ("EVENT_ID") references "EVENT" ("EVENT_ID") match full
on delete set null deferrable initially deferred
----
Baiss Eric Magnusson
<http://w
<http://www.CascadeWebDesign.com>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
email@hidden
This email sent to 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