title: Doctrine ORM Bind Product to Multiple Entities
body: <p>I have businesses, categories and products. Categories are assigned to businesses and products are assigned to categories and businesses.</p>
  
  <p>Reason being, one product can be assigned to different categories in different businesses.</p>
  
  <p>Business and Category entities are working fine, but I am not sure how to write a Product entity to achieve what I need...</p>
  
  <p><strong>Business Entity:</strong></p>
  
  <pre><code>namespace Raiel\AFMage\Entity;
  use Doctrine\Common\Collections\ArrayCollection;
  use Doctrine\ORM\Mapping as ORM;
  
  /**
   * @ORM\Entity()
   * @ORM\Table(name="businesses")
   */
  class Business {
      /**
       * @ORM\Id()
       * @ORM\GeneratedValue(strategy="AUTO")
       * @ORM\Column(type="integer", name="id")
       */
      private $id;
  
      /**
       * @ORM\Column(name="name", type="string", length=64)
       */
      private $name;
  
      /**
       *
       * @ORM\ManyToMany(targetEntity="Category", inversedBy="businesses")
       * @ORM\JoinTable(
       *  name="business_categories",
       *  joinColumns={
       *      @ORM\JoinColumn(name="business_id", referencedColumnName="id")
       *  },
       *  inverseJoinColumns={
       *      @ORM\JoinColumn(name="category_id", referencedColumnName="id")
       *  }
       * )
       */
      private $categories;
  
      /**
       * Default constructor, initializes collections
       */
      public function __construct() {
          $this-&gt;categories = new ArrayCollection();
      }
  }
  </code></pre>
  
  <p><strong>Category Entity:</strong></p>
  
  <pre><code>&lt;?php
  
  namespace Raiel\AFMage\Entity;
  
  use Doctrine\Common\Collections\ArrayCollection;
  use Doctrine\ORM\Mapping as ORM;
  use Gedmo\Mapping\Annotation as Gedmo;
  
  /**
   * @Gedmo\Tree(type="nested")
   * @ORM\Table(name="categories")
   * @ORM\Entity(repositoryClass="Gedmo\Tree\Entity\Repository\NestedTreeRepository")
   */
  class Category {
      /**
       * @ORM\Column(name="id", type="integer")
       * @ORM\Id
       * @ORM\GeneratedValue
       */
      private $id;
  
      /**
       *
       * @ORM\ManyToMany(targetEntity="Business", mappedBy="categories")
       */
      private $businesses;
  
      /**
       * @Gedmo\TreePath
       * @ORM\Column(name="path", type="string", length=3000, nullable=true)
       */
      private $path;
  
      /**
       * @ORM\Column(name="title", type="string", length=64)
       */
      private $title;
  
      /**
       * @Gedmo\TreeLevel
       * @ORM\Column(name="lvl", type="integer")
       */
      private $lvl;
  
      /**
       * @Gedmo\TreeLeft
       * @ORM\Column(name="lft", type="integer")
       */
      private $lft;
  
      /**
       * @Gedmo\TreeRight
       * @ORM\Column(name="rgt", type="integer")
       */
      private $rgt;
  
      /**
       * @Gedmo\TreeRoot
       * @ORM\Column(name="root", type="integer", nullable=true)
       */
      private $root;
  
      /**
       * @Gedmo\TreeParent
       * @ORM\ManyToOne(targetEntity="Category", inversedBy="children")
       * @ORM\JoinColumn(name="parent_id", referencedColumnName="id", onDelete="CASCADE")
       */
      private $parent;
  
      /**
       * @ORM\OneToMany(targetEntity="Category", mappedBy="parent")
       * @ORM\OrderBy({"lft" = "ASC"})
       */
      private $children;
      /**
       * Constructor
       */
      public function __construct() {
          $this-&gt;children   = new ArrayCollection();
          $this-&gt;businesses = new ArrayCollection();
      }
  }
  </code></pre>
  
  <p>Also, $business->addCategory works fine but $category->addBusiness doesn't save to DB.</p>