I'm sure there's a simple solution to this, but I can't fathom what's going on. I have an entity called a Payment and two other entities called User and Household.
A User has many Payments and and a Household has many Payments. This is all mapped as unidirectional manyToOne relationships of the Payment using YAML, like this (hopefully this is in line with the guidance at 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
Database wise, I have three tables, users, payments and households. The payments table has (in addition to it's primary key) two columns called user_id and household_id, which correspond the to primary keys of the other two tables.
The problem is that when I try to persist a new Payment I get an error back from mySql telling me that the user_id column of payments cannot be null. Some digging has established that doctrine is supplying null for both user_id and household_id in the INSERT statement. The object graph is definitely correct.
In addition, I get the following warnings:
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
I've established that the payment_id in question is coming from the referencedColumnNames in my mapping, and that the index is undefined because the array doctrine is searching contains the fields from the opposite side of the relationship, i.e. the Household or the User. But surely it shouldn't be? I think I've followed the guide, but I can't make it work.
I'm using Zend Framework, if it helps, but there's nothing special going on my code. I'm pretty sure it's a mapping problem.
Thanks