Re: Creating related objects and multiple ECs
Re: Creating related objects and multiple ECs
- Subject: Re: Creating related objects and multiple ECs
- From: David LeBer <email@hidden>
- Date: Wed, 17 Feb 2010 09:04:35 -0500
On 2010-02-17, at 6:17 AM, David Avendasora wrote:
>
> On Feb 16, 2010, at 5:31 PM, David LeBer wrote:
>
>> It definitely doesn't work trying to pull an EO in a child ec into it's parent's. i.e:
>>
>> EOEditingContext rootEc = ERXEC.newEditingContext();
>> EOEditingContext childEc = ERXEC.newEditingContext(rootEc);
>> Movie m = Movie.createMovie(rootEc, "Test", null);
>> Studio s = Studio.createStudio(childEc, new BigDecimal(100.00), "Test");
>> Studio localS = s.localInstanceIn(m.editingContext());
>>
>> BOOM: "You attempted to localInstance <org.wocommunity.movies.model.server.Studio pk:"null">, which has not yet committed."
>>
>> I thought I'd gotten a similar message when I tried the other way around, but I probably got distracted and... OOH! SHINY!...
>
> As helpful as Anjo's comment was, I'm going to try to add to it (crazy, I know).
>
> In this example, why not just call childEc.saveChanges() after creating the Studio? That won't actually save it to the DB/ObjectStore, just to the rootEc. Then you can easily just do m.setStudio(s),
Yeah, I know.
I was just being verbose. This code snippet was just demonstrating that although you can call local instance on an uncommitted EO in a parent EC into a child EC, you cannot do the opposite. Mostly for posterity: i.e: Do not attempt to do this.
// This will work
EOEditingContext rootEc = ERXEC.newEditingContext();
EOEditingContext childEc = ERXEC.newEditingContext(rootEc);
Movie m = Movie.createMovie(rootEc, "Test", null);
Studio s = Studio.createStudio(childEc, new BigDecimal(100.00), "Test");
Movie localM = m.localInstanceIn(s.editingContext());
// This will not
EOEditingContext rootEc = ERXEC.newEditingContext();
EOEditingContext childEc = ERXEC.newEditingContext(rootEc);
Movie m = Movie.createMovie(rootEc, "Test", null);
Studio s = Studio.createStudio(childEc, new BigDecimal(100.00), "Test");
Studio localS = s.localInstanceIn(m.editingContext());
> and I don't think you even need to do the localInstance, do you? (It's been a while since I did nested ECs)
Yeah you do.
;david
--
David LeBer
Codeferous Software
'co-def-er-ous' adj. Literally 'code-bearing'
site: http://codeferous.com
blog: http://davidleber.net
profile: http://www.linkedin.com/in/davidleber
twitter: http://twitter.com/rebeld
--
Toronto Area Cocoa / WebObjects developers group:
http://tacow.org
_______________________________________________
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