Re: Duplicating an EO and all its relationships
Re: Duplicating an EO and all its relationships
- Subject: Re: Duplicating an EO and all its relationships
- From: Art Isbell <email@hidden>
- Date: Thu, 31 Jul 2003 12:06:28 -1000
On Thursday, July 31, 2003, at 08:49 AM, Albert Jagnow wrote:
What I am trying to do is to create a duplicate copy of an EO
including
all the relationship objects and save the copies to the database. For
example I have a purchase request EO that has many purchase items, and
each item may have many accounts/grants associated with it (it is
slightly more complicated than this but that is the basic structure).
What I want to do is create a copy of the entire purchase request that
I
can save to the database. Everything would be the exactly the same in
the copy except for of course for the primary and foreign keys (which I
will let EOF create), and some timestamps, and descriptions which I
would set. This seems like it should be very easy, like only a few
lines of code, but I couldn't find an easy way to do it. Anyone have
any suggestions?
The standard Java approach would be to implement clone() in the EO
class. But for good reasons, EOGenericRecord, the EO superclass, does
not implement the Cloneable interface, so its private instance
variables aren't going to be correctly copied.
To copy an EO instance, you'll need to create a new instance, insert
it into an EC as always, then for each attribute, send the new object a
setter message whose argument is the value returned by sending the
original object a getter message. For each relationship, send the new
object an addObjectToBothSidesOfRelationshipWithKey() message the first
of whose arguments is the value returned by sending the original object
a getter message.
So this will likely be more than just a few lines of code.
Aloha,
Art
_______________________________________________
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.