Ticket #1078 (closed defect: fixed)
synchronizeWithArray fails when m-n relationship with n already existing
Description
Failing Code:
$user = new User();
$array = array();
# This will work as expected by adding a new group and a relationship
to the User
$array['Group'][] = array('name' => 'New Group');
# These will all fail with an assortment of error messages
## SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate
entry '1' for key 1
$array['Group'][] = array('id' => 1);
## SQLSTATE[23000]: Integrity constraint violation: 1048 Column
'immigrant_type_id' cannot be null
$group = Doctrine::getTable('Group')->find(1);
$array['Group'][] = $group;
$user->synchronizeWithArray($array);
$user->save();
Example of why this is so useful
/*
# Template
echo input_tag('user[name]');
echo input_tag('user[username]');
echo input_tag('user[Phonenumber][][phonenumber]');
echo select_tag('user[Group][][id]', array('1' => 'Group which already exists');
*/
# Action
$user = $this->getRequestParameter('user');
$User = new User();
$User->synnchronizeWithArray($user);
$User->save();
I've attached a patch to the SynchronizeTestCase.php with a failing test
Attachments
Change History
Note: See
TracTickets for help on using
tickets.