Re: How do I know when an EOEnterpriseObject is removed from an Editi ng Context?
Re: How do I know when an EOEnterpriseObject is removed from an Editi ng Context?
- Subject: Re: How do I know when an EOEnterpriseObject is removed from an Editi ng Context?
- From: Jonathan Rochkind <email@hidden>
- Date: Thu, 09 Jan 2003 10:51:52 -0600
There's no good way for an EO to trap the fact that it has been inserted in
an EC, but never saved, the EC has just been discarded.
Here's how I'd do something along the lines of what you want:
1) First, don't use validateForDelete. Over-ride
propagateForDeleteWithEditingContext instead; you can run into problems
making db changes with validateForDelete. But the propagate... method is
intended for uses closer to what you want here.
2) In awakeFromInsertion, don't actually commit your changes to the db.
Instead of using raw SQL, use normal EOF stuff operating on EOs in the same
EC. If the EC is later committed to the db with saveChanges(), your newly
created EO will be committed to the db, AND the other things you did in
awakeFromInsertion will also be committed to the db. If the EC never ends
up being committed to the db, then neither the new EO nor the extra stuff
associated it will be written to the db.
Hopefully this will give you some ideas. If this won't work for you for
some reason, maybe someone else will have some better ideas depending on
your needs.
--Jonathan
At 10:52 AM 1/9/2003 +1030, MacMullin, Jake (DCS) wrote:
Hi,
I need to do some database manipulation with raw SQL when my objects are
created - so I have overridden awakeFromInsertion to write some stuff to the
DB when my objects are inserted into an editing context. I also need to do
some cleaning up if the object is deleted - so I have overridden
validateForDelete to use raw SQL to delete the stuff from the database. This
works beautifully. Whenever I create an object it writes the stuff I want to
the DB and when it is deleted it cleans up after itself.
However, I have stumbled across a problem. What do I do if the object is
created and inserted in to the editing context, but then the changes are
discarded, like if the 'Cancel' button is pressed in a Direct2Web app or by
revert() being called on the editing context. It seems like the
validateForDelete method isn't called in this case. So how do I know when
one of my custom EOEnterpriseObjects is discarded in this manner?
Regards,
Jake MacMullin
This e-mail is personal. It is not authorised by, nor sent on behalf of, the
Government of South Australia.
_______________________________________________
WebObjects-dev mailing list
email@hidden
http://www.omnigroup.com/mailman/listinfo/webobjects-dev
_______________________________________________
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.