cascaded update of objects with Glorp

Previous Topic Next Topic
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

cascaded update of objects with Glorp

Alain rastoul

I am trying to update a composite object in a database with Glorp.
I have a Customer object with a reference to an Address object.

In my seaside app, I have a ListView that calls a CustomerEditView when I
click on a customer.
edit: aCustomer
 | response |
 response := self call: (self editor new model: aCustomer copy).
 response ifNotNil: [
  self session database update: aCustomer with: response].

(database is a is a facade to the Glorp system, and update: anObject with:
anotherObject perform the variable instance assignments of an object to
another in a glorp unit of work).
when I click on Cancel button in my CustomerEditView, the address is
modified in the list with what has been typed in the form.
(a shallow copy points to the same Address object) so I tryed: ... model:
anObject deepCopy ...
And I have a DuplicatePrimaryKeyException in Glorp when I click on the save
button, because Glorp don't want to have two different objects with the same
primary key - that makes sense.

Do anyone know  a way to do this in Glorp without updating  each field of
the linked object (in the final model, I will have 3 addresses), ie, doing
the update cascade in a simple way. I am thinking about implementing an
updateFrom: anotherObject or copyTo: anotherObject in my Customer and
Address objects but it does not fit right with basic types (String, integers
etc) and I am sure someone had the same problem before me.

Any idea, comments or suggestions are welcome

Thanks in advance,