I have the same question, and I understood my decision when I read.
When I am ready to process the submitted entries, I will first make a request to get the current associations and call this $ original_list array. The submitted list I will call $ submitted_list.
$original_list = array(3,5,7); $submitted_list = array(1,2,3);
Then I just need to find out 1) which elements to remove (no longer exists) and 2) which elements to add (new associations). Elements in both lists are not affected.
$delete_list = array_diff($original_list, $submitted_list); $insert_list = array_diff($submitted_list, $original_list); foreach($delete_list as $item) { // delete $item from DB } foreach($insert_list as $item) { // insert item in db }
I would like to know if others consider this the right decision.
source share