title: Join-Table with metadata, composite key and one to many relationship
body: <p>i am building a cart that can take items with specified versions.</p>
  
  <p>I am using <code>Symfony 2.4.3</code> and <code>Doctrine 2</code></p>
  
  <p>I have following code for three entities, <code>Cart</code>, <code>CartItem</code> and <code>CartItemVersion</code>.</p>
  
  <p><code>Cart.php</code></p>
  
  <pre><code>// ----
  
  /**
   * @ORM\OneToMany(targetEntity="CartItem", mappedBy="cart")
   */
  private $cartItems;
  
  // ----
  </code></pre>
  
  <p><code>CartItem.php</code></p>
  
  <pre><code>// ----
  
  /**
   * @ORM\Id
   * @ORM\ManyToOne(targetEntity="Cart")
   */
  private $cart;
  
  /**
   * @ORM\Id
   * @ORM\ManyToOne(targetEntity="Item")
   */
  private $item;
  
  /**
   * @ORM\OneToMany(targetEntity="CartItemVersion", mappedBy="cartItem")
   */
  private $cartItemVersions;
  
  // ----
  </code></pre>
  
  <p><code>CartItemVersion.php</code></p>
  
  <pre><code>// ----
  
  /**
   * @ORM\Id
   * @ORM\ManyToOne(targetEntity="CartItem")
   */
  private $cartItem;
  
  /**
   * @ORM\Id
   * @ORM\ManyToOne(targetEntity="ItemVersion")
   */
  private $itemVersion;
  
  // ----
  </code></pre>
  
  <p>While updating schema, i got this error.</p>
  
  <pre><code>[Doctrine\ORM\ORMException]
  Column name `id` referenced for relation from CartItemVersion towards CartItem does not exist.
  </code></pre>
  
  <p>Then i gave name to the fields like <code>cartItem_id</code> in <code>CartItemVersion.php</code> and others.</p>
  
  <p>Then updating schema returns,</p>
  
  <pre><code>[Doctrine\DBAL\DBALException]                                                
  An exception occurred while executing 'ALTER TABLE cart_item_version ADD CONSTRAINT FK_4D3EA2E02EA80FC1 FOREIGN KEY (cartItem_id) REFERENCES cart_item (cartItemVersion_id)':
  
  SQLSTATE[HY000]: General error: 1005 Can't create table 'symfony.#sql-3d8_12a' (errno: 150)
  </code></pre>
  
  <p>I have referred Doctrine 2's documentation and followed Use Cases for <code>OrderItem</code> but it seems that this is something because of composite primary keys, but still giving proper names couldn't solve this issue.</p>
  
  <p>Can anyone help?</p>