• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Nested editing context 101 question?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Nested editing context 101 question?


  • Subject: Re: Nested editing context 101 question?
  • From: "Ricardo J. Parada" <email@hidden>
  • Date: Thu, 09 Jul 2009 12:29:48 -0400

Thanks Kieran...

Basically we have some code that loads objects into the database which currently works in a way that violates some of the EOF commandments.  This is not using Wonder.  But we're converting it to Wonder.  

The code works as follows, it creates EOs without inserting them into an editing context.  It sets properties (including relationships) and then validates the object.  Then it checks to see if the object already exists into the database.  If it doesn't I believe it then inserts the EO into the editing context and calls saveChanges, thereby saving the inserted objects to the database.  If on the other hand the object already exists in the database, it then copies the changes to the existing object and then calls saveChanges.  Because the new EO was never inserted into the database then it does not get saved.  Only the changes applied to the existing EOs.  Anyways, that's a brief description of how it works (pre-Wonder code).

We are migrating to Wonder and I've seen code like that throw an exception, when one starts setting to-one relationships in an EO that has not been inserted into the database.  The exception says that the EOs have different editing contexts, i.e. one has null as the editing context and the other one has a non-null editing context.

Anyways, I'm trying to find out how to rewrite that code so it does not violate the EOF commandments and avoid the exception rightfully thrown by Wonder.

My first thought was a child editing context, create the new EO in a child editing context.  If you decide it does not exist in the database then save once to push to the parent, and then save the parent editing context to save to the database.  If it does exist then apply the changes to the existing EOs in the parent editing context and save that and simply throw away or revert the child editing context.

Anyways, something like that.  But it sounds to me like a peer editing context would work equally well.  Specially if they will both require that when I set relationships I get a local instance of the EO it wants to reference.

:-)




On Jul 9, 2009, at 12:09 PM, Kieran Kelleher wrote:

You should local instance it because a different ec is a different ec whether nested or not. I am not a fan of nested ec's and generally do not design them into my app architecture.

On Jul 9, 2009, at 11:51 AM, Ricardo J. Parada wrote:


If I have an EO in a child editing context, can it reference an EO in the parent editing context?
Or do I have to copy the EO from the parent editing context to the child editing context first?

I should know this one... But I don't use nested editing contexts that often, so I forgot.   :-)

Thanks

 _______________________________________________
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

References: 
 >Nested editing context 101 question? (From: "Ricardo J. Parada" <email@hidden>)
 >Re: Nested editing context 101 question? (From: Kieran Kelleher <email@hidden>)

  • Prev by Date: AjaxObserveField - next Field
  • Next by Date: Re: AjaxObserveField - next Field
  • Previous by thread: Re: Nested editing context 101 question?
  • Next by thread: AjaxObserveField - next Field
  • Index(es):
    • Date
    • Thread