title: Doctrine 2 - How to design an Entity having subtree type attribute from main tree type Entity
body: <p>I have a main Entity Segment that has one-to-many categories and category has one-to-many items, so 3 level tree structure</p>
  
  <pre><code>class Segment
  {
  
      /**
       * @ORM\Id
       */
      protected $id;
  
      /**
       * @ORM\OneToMany(targetEntity="Category", mappedBy="segment")
       * @ORM\JoinColumn(name="segment_id", referencedColumnName="id")
       */
      protected $categories;
  }  
  
  class Category
  {
  
      /**
       * @ORM\Id
       */
      protected $id;
  
      /**
       * @ORM\ManyToOne(targetEntity="Segment")
       * @ORM\JoinColumn(name="segment_id", referencedColumnName="id")
       */
      protected $segment;
  
      /**
       * @ORM\OneToMany(targetEntity="Item", mappedBy="category")
       * @ORM\JoinColumn(name="category_id", referencedColumnName="id")
       */
      protected $items;
  }
  
  class Item
  {
  
      /**
       * @ORM\Id
       */
      protected $id;
  
      /**
       * @ORM\ManyToOne(targetEntity="Category")
       * @ORM\JoinColumn(name="category_id", referencedColumnName="id")
       */
      protected $category;
  }
  </code></pre>
  
  <p>SQL Tables  </p>
  
  <pre><code>CREATE TABLE segment (
      id INT PRIMARY KEY AUTO_INCREMENT NOT NULL,
      name VARCHAR(100) NOT NULL,
  )
  
  CREATE TABLE segment_category 
  (
      id INT PRIMARY KEY AUTO_INCREMENT NOT NULL,
      segment_id INT NOT NULL,
      name VARCHAR(100) NOT NULL,
      FOREIGN KEY(segment_id) REFERENCES segment(id)
  )
  CREATE TABLE segment_item 
  (
      id INT PRIMARY KEY AUTO_INCREMENT NOT NULL,
      category_id INT NOT NULL,
      name VARCHAR(100) NOT NULL,
      FOREIGN KEY(category_id) REFERENCES segment_category(id)
  )
  </code></pre>
  
  <p>and here is my Entity Company that has sub-segment from Segment</p>
  
  <pre><code>class Company
  {
      /**
       * @ORM\Id
       */
      protected $id;
  
      /**
       * @ORM\ManyToMany(targetEntity="Segment")
       * -- What here to add? Is this correct ?--
       * @ORM\JoinTable(name="company_segment_linker",
       *      joinColumns={@ORM\JoinColumn(name="company_id", referencedColumnName="id")},
       *      inverseJoinColumns={@ORM\JoinColumn(name="item_id", referencedColumnName="id")}
       * )
       */
      protected $segments;
  }
  </code></pre>
  
  <p>Company SQL table that determines which Segment (also Categories and Items) belongs to Company.</p>
  
  <pre><code>CREATE TABLE company_segment_linker 
  (
      company_id INT NOT NULL,
      item_id INT NOT NULL,
      FOREIGN KEY(company_id) REFERENCES company(id),
      FOREIGN KEY(item_id) REFERENCES segment_item(id)
  ) 
  </code></pre>
  
  <p>Segment data structure example (numbers represent IDs):</p>
  
  <ol>
  <li>seg1
  <ol>
  <li>cat1
  <ol>
  <li>item1</li>
  <li>item2</li>
  <li>item3</li>
  </ol></li>
  <li>cat2
  <ol>
  <li>item4</li>
  <li>item5</li>
  </ol></li>
  </ol></li>
  <li>seg2
  <ol>
  <li>cat3
  <ol>
  <li>item6</li>
  </ol></li>
  <li>cat4
  <ol>
  <li>item7</li>
  <li>item8</li>
  </ol></li>
  </ol></li>
  </ol>
  
  <p>Company com1 that has a sub-segment like this:</p>
  
  <ol>
  <li>seg1
  <ol>
  <li>cat1
  <ol>
  <li>item2</li>
  <li>item3        </li>
  </ol></li>
  <li>cat2
  <ol>
  <li>item5</li>
  </ol></li>
  </ol></li>
  <li>seg2
  <ol>
  <li>cat4
  <ol>
  <li>item8 </li>
  </ol></li>
  </ol></li>
  </ol>
  
  <p>So I would store only company fk_id and item fk_ids in company_segment_linker table<br>
  company_id | item_id<br>
  1          | 2<br>
  1          | 3<br>
  1          | 5<br>
  1          | 8<br>
  because from item table i can refer to category and from category table to segment.</p>
  
  <p>My question is, is this all possible in Doctrine2, to create a sub-segment only from item foreign key(s) and if yes how to write the annotation(s)? Or must I use another approach to achieve this ?
  Thanks for your help.
  PS: Sorry for my english :/ </p>