title: Doctrine - one table with tags for multiple entities
body: <p>I want to create Tag entity class, with taxonomy vocabulary, that will be used by multiple entities.
  Is there any possibility, to create manytomany relations with three columns?
  I need to store tag id, entity id, and entity class name.</p>
  
  <p>So i have now:</p>
  
  <pre><code>&lt;?php
  /**
   * Taxonomy
   *
   * @ORM\Table(
   *    name="tag_taxonomy",
   *    indexes={
   *        @ORM\Index(name="tag_taxonomy_namex", columns={"name"})
   *    }
   * )
   * @ORM\HasLifecycleCallbacks
   * @ORM\Entity
   */
  class Taxonomy
  {
      /**
       * @var integer
       *
       * @ORM\Column(name="id", type="integer")
       * @ORM\Id
       * @ORM\GeneratedValue(strategy="AUTO")
       */
      protected $id;
      /**
       * @var string
       * @ORM\Column(name="name", type="string", length=50)
       */
      protected $name;
      /**
       * @ORM\OneToMany(targetEntity="Tag", mappedBy="taxonomy", fetch="LAZY")
       */
      protected $tags;
      // .....
  }
  </code></pre>
  
  <p>Tag table:</p>
  
  <pre><code>&lt;?php
  /**
   * Tag
   *
   * @ORM\Table(
   *     name="tag",
   *    indexes={
   *        @ORM\Index(name="namex", columns={"name"})
   *    }
   * )
   * @ORM\HasLifecycleCallbacks
   * @ORM\Entity
   */
  class Tag
  {
      /**
       * @var integer
       *
       * @ORM\Column(name="id", type="integer")
       * @ORM\Id
       * @ORM\GeneratedValue
       */
      protected $id;
      /**
       * @var string
       * @ORM\Column(name="name", type="string", length=50)
       */
      protected $name;
      /**
       * @ORM\ManyToOne(targetEntity="Taxonomy", inversedBy="tags", fetch="LAZY")
       * @ORM\JoinColumn(name="taxonomy_id", referencedColumnName="id", onDelete="SET NULL")
       */
      protected $taxonomy;
      // ....
  }
  </code></pre>
  
  <p>Relation table:</p>
  
  <pre><code>&lt;?php
  /**
   * @ORM\Table(
   *     name="tag_tagging",
   *     uniqueConstraints={
   *        @ORM\UniqueConstraint(name="tagging_idx", columns={"tag_id", "entity_name", "record_id"})
   *    },
   *    indexes={
   *        @ORM\Index(name="entity_name_idx", columns={"entity_name", "record_id"})
   *    }
   * )
   * @ORM\HasLifecycleCallbacks
   * @ORM\Entity
   */
  class Tagging
  {
      /**
       * @var integer $id
       *
       * @ORM\Column(name="id", type="integer")
       * @ORM\Id
       * @ORM\GeneratedValue(strategy="AUTO")
       */
      protected $id;
      /**
       * @ORM\ManyToOne(targetEntity="Tag", inversedBy="tagging", cascade="ALL")
       * @ORM\JoinColumn(name="tag_id", referencedColumnName="id", onDelete="CASCADE")
       **/
      protected $tag;
      /**
       * @var string
       * @ORM\Column(name="entity_name", type="string", length=100)
       */
      protected $entityName;
      /**
       * @var int
       * @ORM\Column(name="record_id", type="integer")
       */
      protected $recordId;
      // .....
  }
  </code></pre>
  
  <p>So i have already relation table with 3 columns as key:
  "tag_id", "entity_name", "record_id".
  Now any idea how to create relation with any entity, to tag table?
  Maybe Tagging entity is not needed at all?</p>
  
  <p>I wonder what is the best way, to create Tag entity for any entity type.
  So i can use tags for Users, Articles, anything.
  Of course there can be manytomany relation that will create separate relation table for every entity right? But is the right way?</p>