title: Doctrine: Multidimensional Arrays in Doctrine 2
body: <p>I am working with Symfony2 and Doctrine2 and I have an object that needs to implement multiple arrays of arrays. The only solution I came up with is to create a bridge object between my main object and the object it is referencing.</p>
  
  <p>So this would be my object:</p>
  
  <pre><code>/**
   * @ORM\Table()
   */
  class MyObject
  {
      /**
       * @var integer
       *
       * @ORM\Column(name="id", type="integer")
       * @ORM\Id
       * @ORM\GeneratedValue(strategy="AUTO")
       */
      private $id;
  
      /**
       * @ORM\OneToMany(targetEntity="CollectionOfObjectX", mappedBy="parent", cascade={"all"})
       **/
      private $collectionsOfObjectX;
  
      public function __construct() {
          $this-&gt;collectionsOfObjectX = new ArrayCollection();
      }
  
      ... (Getters and Setters)
  
  }
  </code></pre>
  
  <p>This would be the Bridge between the object and some other object</p>
  
  <pre><code>/**
   * @ORM\Table()
   */
  class CollectionOfObjectX
  {
      /**
       * @var integer
       *
       * @ORM\Column(name="id", type="integer")
       * @ORM\Id
       * @ORM\GeneratedValue(strategy="AUTO")
       */
      private $id;
  
      /**
       * @ORM\ManyToOne(targetEntity="ObjectX",     inversedBy="collectionsOfObjectX", cascade={"all"})
       * @ORM\JoinColumn(name="parent_id", referencedColumnName="id")
       **/
      private $parent;
  
      /**
       * @ORM\ManyToMany(targetEntity="MyObject",     cascade={"all"})
       * @ORM\JoinTable(
       *      joinColumns={@ORM\JoinColumn(name="local_id", referencedColumnName="id")},
       *      inverseJoinColumns={@ORM\JoinColumn(name="foreign_id", referencedColumnName="id")}
       *      )
       **/
      private $items;
  
      public function __construct() {
          $this-&gt;items = new ArrayCollection();
      }
  
  .... (Getters and Setters)
  
  }
  </code></pre>
  
  <p>And this would be the referenced object</p>
  
  <pre><code>/**
   * @ORM\Table()
   */
  class ObjectX
  {
      /**
       * @var integer
       *
       * @ORM\Column(name="id", type="integer")
       * @ORM\Id
       * @ORM\GeneratedValue(strategy="AUTO")
       */
      private $id;  
  
  ... (Some Properties, Getters and Setters)
  }  
  </code></pre>
  
  <p>So while this works, it requires a Bridge Object for each possible relation between MyObject and any other object it references, implying a lot of duplicate code.</p>
  
  <p>Is there a better way?</p>