Re: multiple objects in an EO, how to saveChanges() on only one
Re: multiple objects in an EO, how to saveChanges() on only one
- Subject: Re: multiple objects in an EO, how to saveChanges() on only one
- From: Dev WO <email@hidden>
- Date: Sun, 16 Oct 2005 00:08:39 +0200
Thanks Ken and Nathan,
I'll try to implement that and come back if I still have problems;)
and sorry about the terminology mix up, might be the fact I'm too
tired;)
Xavier
Xavier,
You seem to have some terminology mixed up - if you call an editing
context an EO, you're going to confuse a lot of people. An EO is
an Enterprise Object, so it's A, B, or C - not the EC.
This is a perfect example to use another editing context. You can
just create a new one like in Nathan's code. As his code shows, be
sure to lock and unlock the context, since only the default editing
context is locked and unlocked automatically for you.
I would add that you should always have a try/finally block:
try
{
newEC.lock();
newEC.saveChanges();
} finally {
newEC.unlock();
newEC.dispose(); // if you really want to get rid of it
}
The whole idea of an editing context is you might want to provide
your users with multiple 'editing' 'contexts' (beautiful naming
here). This means that you can have other eo's edited in a
different context, and they will never be touched. This is the
best (and really only) way to approach saving some things and not
others.
Ken
On Oct 15, 2005, at 5:59 PM, Dev WO wrote:
Hi Ken,
pretty fast answer:)
ok, to summarize, I have different type of action:
-posting a comment on a "news"
-selecting product for a shopping cart
What I was doing was to add both 2 objects (cartItem and
commentItem) into an eo (the defaulteditingContext).
But I'd like the logged user to be able to post a comment even if
he has a cart with some items (I mean he's still doing his
shopping at the time of the comment).
So my cartItem object can't be "saved" because it still missing
some information to complete the order (the order can be
incomplete in fact), but actually if the user try to post a
comment, I got an exception because of the incomplete cartItem.
So I should create another eo for handle these tasks separately?
Can it be 2 default EditingContext?
Should/can I initialize them in the session so they will both be
accessible from different WOComponent?
:)
Xavier
You can't. Can you enlighten the list as to why you want to do
this?
The proper thing to do is to have more than one editing context.
Ken
On Oct 15, 2005, at 5:46 PM, Dev WO wrote:
Hi list,
I have different object in the editing context, lets say a, b
and c.
I need to save changes to the database only for b (for example;)).
I though b().editingContext().saveChanges() would do the trick,
but it also tries to save all other object...
Anyone with a clue on how to handle this?
Thanks a lot
Xavier
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
40anderhome.com
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