gpt4 book ai didi

forms - 使用Doctrine的symfony 1.4形式中的奇怪的多对多行为

转载 作者:行者123 更新时间:2023-12-01 13:32:56 25 4
gpt4 key购买 nike

我在表单处理中遇到了意外行为,在Doctrine中遇到了symfony 1.4。我有一个表,它与自身具有多对多关系:

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

PersonTeacher:
columns:
teacher_id: { type: integer, primary: true }
student_id: { type: integer, primary: true }

在Person中,我有一个在PersonForm中调用的方法,可用于自定义小部件:
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();
}

没有该方法调用,Doctrine可以从PersonTeacher正确地插入和删除记录。但是,当我从PersonForm调用该方法时,将在保存表单(从日志中获取)时运行以下UPDATE:
Doctrine_Connection->update(object('PersonTeacherTable'), array('student_id' => '9'), array('teacher_id' => '9', 'student_id' => '6'))

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

回溯:
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 person_teacher 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('PersonTeacherTable'), 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('PersonTeacher'))
in SF_SYMFONY_LIB_DIR/plugins/sfDoctrinePlugin/lib/vendor/doctrine/Doctrine/Connection/UnitOfWork.php line 89 ...
at Doctrine_Connection_UnitOfWork->saveGraph(object('PersonTeacher'))
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 ...

仅当多对多引用同一张表时,才会发生这种情况。我也有一对多引用自己的表的方法,它可以正常工作。

这铃响了吗?

最佳答案

关于forms - 使用Doctrine的symfony 1.4形式中的奇怪的多对多行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5010146/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com