title: ManyToOne mapping with Doctrine and undefined index warnings
body: <p>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 <code>Payment</code> and two other entities called <code>User</code> and <code>Household</code>.</p>
  
  <p>A <code>User</code> has many <code>Payment</code>s and and a <code>Household</code> has many <code>Payment</code>s. This is all mapped as unidirectional manyToOne relationships of the <code>Payment</code> using YAML, like this (hopefully this is in line with the guidance at <a href="http://docs.doctrine-project.org/projects/doctrine-orm/en/2.1/reference/association-mapping.html#many-to-one-unidirectional" rel="nofollow">http://docs.doctrine-project.org/projects/doctrine-orm/en/2.1/reference/association-mapping.html#many-to-one-unidirectional</a>) - </p>
  
  <pre><code>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
  </code></pre>
  
  <p>Database wise, I have three tables, <code>users</code>, <code>payments</code> and <code>households</code>. The <code>payments</code> table has (in addition to it's primary key) two columns called <code>user_id</code> and <code>household_id</code>, which correspond the to primary keys of the other two tables.</p>
  
  <p>The problem is that when I try to persist a new <code>Payment</code> I get an error back from mySql telling me that the <code>user_id</code> column of <code>payments</code> cannot be null. Some digging has established that doctrine is supplying <code>null</code> for both <code>user_id</code> and <code>household_id</code> in the INSERT statement. The object graph is definitely correct. </p>
  
  <p>In addition, I get the following warnings: </p>
  
  <pre><code>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
  </code></pre>
  
  <p>I've established that the <code>payment_id</code> in question is coming from the <code>referencedColumnName</code>s in my mapping, and that the index is undefined because the array doctrine is searching contains the fields from the <em>opposite</em> side of the relationship, i.e. the <code>Household</code> or the <code>User</code>. But surely it shouldn't be? I think I've followed the guide, but I can't make it work.</p>
  
  <p>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.</p>
  
  <p>Thanks</p>