Re: Editing Context Question
Re: Editing Context Question
- Subject: Re: Editing Context Question
- From: Jonathan Rochkind <email@hidden>
- Date: Tue, 16 Mar 2004 12:11:42 -0600
At 11:55 AM -0600 3/16/04, James Cicenia wrote:
Hello _
I need to create a new instance of two of my eo objects and then relate them.
I then need to pass these to my next page.
Okay, just do it.
SomeClass someEO = new SomeClass();
//Always immediately insert! Is a very good rule.
ec.insertObject( someEO );
OtherClass otherEO = new OtherClass();
ec.insertObject( otherEO );
//There are other ways to do this than addObjectToBothSides..., but
that's a good way.
someEO.addObjectToBothSidesOfRelationshipWithKey( otherEO,
"nameOfRelationship");
ComponentClass nextPage = (ComponentClass) pageWithName("ComponentClass");
nextPage.setSomething( someEO );
I first created the new instances and then inserted them with ec.insertObject
finally I related them with addObjectToBothSidesOfRelationship.
Now on my next page how do I access them?
Well, you've got to pass them on to your next page. Put them in some
iVar in the next page. Then you can access them from that iVar. The
fact that they are EOs are nothing special; if you want to be able to
access an object, you've got to store it somewhere first. Or else
it'll be inaccessible and just get garbage collected. (Well, this
isn't actually true in the case of EOs---if they've got changes, the
EC will keep a strong reference to them, and they won't be GC'd.
But, anyway, that doesn't matter---if you want to be able to access
an EO, you've got to keep a reference to it somewhere that you can
access!).
I am a bit confused on this issue.
Also, will the ec automagically relate them? I wouldn't think they
had a GlobalID
yet?
They do have an EOGlobalID, as soon as they are inserted into the EC.
It's an EOTemporaryGlobalID, instead of an EOKeyGlobalID. They do
not yet have a PK assigned, true.
But you don't need to worry about any of that technical stuff---yes,
regardless of what's happening under the hood, EOF is perfectly
capable of tracking the fact that two objects are put in
relationship, even if one or both of those objects has not yet been
inserted into the db. When you call saveChanges(), they will be
inserted into the db, and all foreign keys will be set properly.
Just trust EOF here, it does fine.
There's nothing 'automagic' about EOF relating the two objects. They
will be regarded as related if and only if and when you set the
relationship, such as with the addObjectToBothSides... method. I
suppose the 'automagic' part is when EOF does the right thing to the
database upon saveChanges(). It will.
--Jonathan
Thanks,
James Cicenia
_______________________________________________
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.
_______________________________________________
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.