【发布时间】:2012-07-05 14:36:58
【问题描述】:
我确信有一个简单的解决方案,但我无法理解发生了什么。我有一个名为 Payment 的实体和另外两个名为 User 和 Household 的实体。
一个User 有很多Payments,一个Household 有很多Payments。这都使用 YAML 映射为 Payment 的单向多对一关系,就像这样(希望这符合 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_id 和household_id,它们对应于其他两个表的主键。
问题是当我尝试持久化一个新的Payment 时,我从mySql 收到一个错误,告诉我payments 的user_id 列不能为空。一些挖掘已经确定该学说在 INSERT 语句中为 user_id 和 household_id 提供 null。对象图绝对正确。
此外,我收到以下警告:
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 来自我的映射中的 referencedColumnNames,并且索引未定义,因为正在搜索的数组原则包含来自 对面 关系的一方,即Household 或User。但肯定不应该吗?我想我已经按照指南进行了操作,但我无法让它发挥作用。
我正在使用 Zend 框架,如果它有帮助的话,但我的代码并没有什么特别之处。我很确定这是一个映射问题。
谢谢
【问题讨论】:
标签: php doctrine-orm