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 protected])
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com
This email sent to [email protected]