Re: How to delete an EO?
Re: How to delete an EO?
- Subject: Re: How to delete an EO?
- From: Chuck Hill <email@hidden>
- Date: Sat, 17 Apr 2004 11:25:57 -0700
At 09:28 AM 17/04/2004 -0700, Glenn L. Austin wrote:
>on 4/17/04 8:47 AM, Chuck Hill at email@hidden wrote:
>
>> public WOComponent deleteRecord()
>> {
>> userRecord().editingContext().deleteObject(userRecord());
>> userRecord().editingContext().saveChanges();
>> return null;
>> }
>>
>> Looks correct to me. Are you getting an exception or error message?
>> What happens? If you are not seeing an exception or error then
>> something someplace else is wrong.
>
>I see a potential problem. I would code it like this:
>
> public WOComponent deleteRecord()
> {
> EOEditingContext context = userRecord().editingContext();
>
> context.deleteObject(userRecord());
> context.saveChanges();
>
> return null;
> }
>
>That way, if the context happens to change due to the deleteObject, the
>saveChanges() will continue to work.
>
The context never changes. Not in this case, not in any case. While you
can have multiple instances of an *eo* in several editing contexts, each is
represented by a unique Java object. The Java objects do not move between
editing contexts. userRecord().editingContext() will return null - but
only after the deletion has been processed.
And even if it did change contexts, your code would be saving the context
that the object was no longer in - hardly likely to work!
Chuck
--
Chuck Hill email@hidden
Global Village Consulting Inc. http://www.global-village.net
_______________________________________________
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.