Re: Duplicate records
Re: Duplicate records
- Subject: Re: Duplicate records
- From: Art Isbell <email@hidden>
- Date: Tue, 22 Jun 2004 10:34:08 -1000
On Jun 22, 2004, at 3:16 AM, Yves Custeau wrote:
Is there an easier way to duplicate database records using EOF.
Copying objects of any kind (not just EO's) is more involved than it
might appear. If you're not familiar with shallow vs. deep copies, see
the Object.clone() Java doc for a brief discussion. You will need to
do a "somewhat deep" Order copy if you need to copy OrderItems to add
them to the new Order.orderItems relationship.
So far I do it this way:
1- Fetch the record using the EODisplayGroup
2- Copy the record in a new EOGenericRecord object
Be careful copying to-many relationships. EO's that are members of a
to-many relationship can't be members of the same to-many relationship
in a different EO. I.e., you can't shallow copy a to-many
relationship. In your case, an OrderItem in the Order.orderItems
relationship of one Order cannot be in the same relationship of another
Order. I.e., an OrderItem can have only one Order. There may be
exceptions to this statement, but someone else will have to point them
out.
3- Do an insert on the DisplayGroup
4- Assign each Displaygroup attribute to the Generic Record attribute
5- Save the changes using the Editing Context
This seems cumbersome for such an advanced framework but I have not
found a
better way of doing it?
It's cumbersome because you're using a WODisplayGroup :-)
In your Order EO class, you could implement a "duplicate" method that
would create a new Order object, insert it into the original Order
object's editing context, copy the attribute and to-one relationship
values, and return this partial duplicate object. Don't name this
method "clone" because it's not a true Java clone. If you want to copy
the orderItems relationship, then OrderItem will need to implement a
"duplicate" method as well. This would avoid the need to implement
this duplication functionality outside of your EO class
implementations.
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.