我确信有一个简单的解决方案,但我无法理解发生了什么。我有一个名为 a 的实体Payment和另外两个名为Userand的实体Household。
AUser有很多Payments 并且 aHousehold有很多Payments。这都被映射为Payment使用 YAML 的单向多对一关系,像这样(希望这符合http://docs.doctrine-project.org/projects/doctrine-orm/en/2.1/reference/association上的指导-mapping.html#many-to-one-unidirectional ) -
Payment:
type: entity
table: payments
id:
_id:
type: integer
column: payment_id
generator:
strategy: AUTO
manyToOne:
_user:
targetEntity: Application_Model_User
joinColumn:
name: user_id
referencedColumnName: payment_id
_household:
targetEntity: Application_Model_Household
joinColumn:
name: household_id
referencedColumnName: payment_id
数据库方面,我有三个表users,payments和households。该payments表(除了它的主键之外)有两列称为user_idand household_id,它们对应于其他两个表的主键。
问题是,当我尝试坚持一个新的时,Payment我从 mySql 收到一个错误,告诉我该user_id列payments不能为空。一些挖掘已经确定该学说在 INSERT 声明中和null两者都提供。对象图绝对正确。user_idhousehold_id
此外,我收到以下警告:
Notice: Undefined index: payment_id in [..]/library/Doctrine/ORM/Persisters/BasicEntityPersister.php on line 511
Notice: Undefined index: in [..]/library/Doctrine/ORM/Persisters/BasicEntityPersister.php on line 511
Notice: Undefined index: payment_id in [..]/library/Doctrine/ORM/Persisters/BasicEntityPersister.php on line 511
Notice: Undefined index: in [..]/library/Doctrine/ORM/Persisters/BasicEntityPersister.php on line 511
我已经确定payment_id问题来自referencedColumnName我的映射中的 s ,并且索引未定义,因为数组原则正在搜索包含来自关系另一侧的字段,即 theHousehold或User. 但肯定不应该吗?我想我已经按照指南进行了操作,但我无法使其正常工作。
如果有帮助,我正在使用 Zend Framework,但我的代码没有什么特别之处。我很确定这是一个映射问题。
谢谢