Dear Agavi Users,

I am looking for advice on the best approach to synchronisation of data 
entities with a 1:n relationship in a REST system.

Consider the form http://pastebin.com/c9NJH72k

The primary entity is Person, which has one or more Address. When a user wants 
to edit a Person via a form, they can add and remove addresses and the form is 
dynamically updated with Javascript. The form is posted with the person id in 
the URL. 

In the case of adding a new addresses, there is no problem. In the case of 
editing addresses, also there is no problem since existing entities are 
identified by a hidden address id.

However the main problem arises when handling removal of addresses. What is the 
best way to handle the post back of data where addresses are removed?

I've considered the problems and have come up with a few ideas:

1. When the data is posted back all existing address entities are deleted and 
any new ones specified in the form are added. However this leads to problems 
with associations to other entities as primary keys will always change.
2. The form dynamically includes a 'removed_address_id' and deletes those 
records specifically. However, this means there is a strong JS dependency.
3. The system performs some sort of synchronisation by loading all addresses 
for a person and then removes, updates or adds the records accordingly. However 
this seems to present a possible overhead when dealing with many associations.

Is there a more fundamentally better approach to designing this common scenario?

Kind regards

Hash (hzilla)
_______________________________________________
users mailing list
[email protected]
http://lists.agavi.org/mailman/listinfo/users

Reply via email to