Hello,

I am encountering unexpected behavior with form processing, symfony 1.4 with Doctrine. I have a table which has a many-to-many relationship to itself:

Person:
  [...]
  relations:
    Teachers:
      class: Person
      refClass: PersonTeacher
      local: student_id
      foreign: teacher_id
      foreignAlias: Students

In Person, I have a method which gets called in PersonForm for use in a custom widget:

public function getTeachersOrderByName()
{
  $q = Doctrine::getTable('Person')
    ->createQuery('t')
    ->leftJoin('t.Students s')
    ->where('s.id = ?', $this->getId())
    ->orderBy('t.last_name, t.first_name ASC');

  return $q->execute();
}

Without that method call, Doctrine correctly INSERTs and DELETEs records from PersonTeacher. But when I call that method in the PersonForm, the following UPDATE is run on saving the form [taken from the logs]:

Doctrine_Connection->update(object('PersonTeacherTable'), array('student_id' => '9'), array('teacher_id' => '9', 'student_id' => '6'))

which throws

SQLSTATE[23000]: Integrity constraint violation: 19 columns teacher_id, student_id are not unique

Backtrace:

at Doctrine_Connection_Statement->execute(array('9', '9', '6'))
in SF_SYMFONY_LIB_DIR/plugins/sfDoctrinePlugin/lib/vendor/doctrine/Doctrine/Connection.php line 1042 ... at Doctrine_Connection->exec('UPDATE teacher_person SET student_id = ? WHERE teacher_id = ? AND student_id = ?', array('9', '9', '6')) in SF_SYMFONY_LIB_DIR/plugins/sfDoctrinePlugin/lib/vendor/doctrine/Doctrine/Connection.php line 653 ... at Doctrine_Connection->update(object('TeacherPersonTable'), array('student_id' => '9'), array('teacher_id' => '9', 'student_id' => '6')) in SF_SYMFONY_LIB_DIR/plugins/sfDoctrinePlugin/lib/vendor/doctrine/Doctrine/Connection/UnitOfWork.php line 534 ...
at Doctrine_Connection_UnitOfWork->update(object('TeacherPerson'))
in SF_SYMFONY_LIB_DIR/plugins/sfDoctrinePlugin/lib/vendor/doctrine/Doctrine/Connection/UnitOfWork.php line 89 ...
at Doctrine_Connection_UnitOfWork->saveGraph(object('TeacherPerson'))
in SF_SYMFONY_LIB_DIR/plugins/sfDoctrinePlugin/lib/vendor/doctrine/Doctrine/Record.php line 1718 ...
at Doctrine_Record->save(object('Doctrine_Connection_Sqlite'))
in SF_SYMFONY_LIB_DIR/plugins/sfDoctrinePlugin/lib/vendor/doctrine/Doctrine/Collection.php line 910 ...
at Doctrine_Collection->save(object('Doctrine_Connection_Sqlite'), 1)
in SF_SYMFONY_LIB_DIR/plugins/sfDoctrinePlugin/lib/vendor/doctrine/Doctrine/Connection/UnitOfWork.php line 136 ...
at Doctrine_Connection_UnitOfWork->saveGraph(object('Person'))
in SF_SYMFONY_LIB_DIR/plugins/sfDoctrinePlugin/lib/vendor/doctrine/Doctrine/Record.php line 1718 ...
at Doctrine_Record->save(object('Doctrine_Connection_Sqlite'))
in SF_SYMFONY_LIB_DIR/plugins/sfDoctrinePlugin/lib/vendor/doctrine/Doctrine/Collection.php line 910 ...
at Doctrine_Collection->save(object('Doctrine_Connection_Sqlite'), )
in SF_SYMFONY_LIB_DIR/plugins/sfDoctrinePlugin/lib/vendor/doctrine/Doctrine/Connection/UnitOfWork.php line 445 ...
at Doctrine_Connection_UnitOfWork->saveAssociations(object('Person'))
in SF_SYMFONY_LIB_DIR/plugins/sfDoctrinePlugin/lib/vendor/doctrine/Doctrine/Connection/UnitOfWork.php line 142 ...145.
at Doctrine_Connection_UnitOfWork->saveGraph(object('Person'))
in SF_SYMFONY_LIB_DIR/plugins/sfDoctrinePlugin/lib/vendor/doctrine/Doctrine/Record.php line 1718 ...
at Doctrine_Record->save(object('Doctrine_Connection_Sqlite'))
in SF_SYMFONY_LIB_DIR/form/addon/sfFormObject.class.php line 161 ...
at sfFormObject->doSave(object('Doctrine_Connection_Sqlite'))
in SF_ROOT_DIR/lib/form/doctrine/base/BasePersonForm.class.php line 116 ...
at BasePersonForm->doSave(object('Doctrine_Connection_Sqlite'))
in SF_SYMFONY_LIB_DIR/form/addon/sfFormObject.class.php line 130 ...

This only occurs when the many-to-many refers to the same table. I also have a one-to-many referring to its own table, and it works correctly. Is this a known issue?

Thank you very much,

--
Yitzchak Schaffer

--
If you want to report a vulnerability issue on symfony, please send it to 
security at symfony-project.com

You received this message because you are subscribed to the Google
Groups "symfony users" group.
To post to this group, send email to symfony-users@googlegroups.com
To unsubscribe from this group, send email to
symfony-users+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/symfony-users?hl=en

Reply via email to