title: Doctrine Dql for One-To-Many, Unidirectional with Join Table
body: <p>So I've read the following <a href="http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/association-mapping.html#one-to-many-unidirectional-with-join-table" rel="nofollow">article</a>.</p>
  
  <p>I've done something similar with my own entities and am trying to create a DQL.</p>
  
  <p>DQL: </p>
  
  <pre><code>$em = $this-&gt;getDoctrine()-&gt;getManager();
  $query = $em-&gt;createQuery(
      'SELECT s,st,tt
       FROM CrmClientBundle:Session s
       INNER JOIN s.session_treatments st
       INNER JOIN st.treatment_type_id tt
       WHERE s.client_id = ' . $id
  );
  $sessions = $query-&gt;getResult();
  </code></pre>
  
  <p>I receive the following error though: </p>
  
  <pre><code>[Semantical Error] line 0, col 152 near 'tt
  ': Error: Class Crm\ClientBundle\Entity\TreatmentType has no association named
  treatment_type_id 
  </code></pre>
  
  <p>However if I remove the second join and check the symfony profiler it creates the following query which seems to me that I have created my entities properly:</p>
  
  <pre><code>SELECT 
    s0_.id AS id0, 
    s0_.client_id AS client_id1, 
    s0_.date AS date2, 
    s0_.session_id AS session_id3, 
    s0_.session_type AS session_type4, 
    s0_.session_cost AS session_cost5, 
    s0_.products_bought AS products_bought6, 
    s0_.products_cost AS products_cost7, 
    s0_.total_cost AS total_cost8, 
    s0_.total_paid AS total_paid9, 
    s0_.notes AS notes10, 
    t1_.id AS id11, 
    t1_.type AS type12, 
    t1_.cost AS cost13, 
    t1_.category_id AS category_id14 
  FROM 
    sessions s0_ 
    INNER JOIN session_treatments s2_ ON s0_.id = s2_.session_id 
    INNER JOIN treatment_types t1_ ON t1_.id = s2_.treatment_type_id 
  WHERE 
    s0_.client_id = 1
  </code></pre>
  
  <p>Crm\ClientBundle\Session.php:</p>
  
  <pre><code>/**
   * @ORM\Entity
   * @ORM\Table(name="sessions")
   */
  class Session {
  /**
   * @ORM\Id
   * @ORM\Column(type="integer")
   * @ORM\GeneratedValue(strategy="AUTO")
   */
  private $id;
  
  /** @ORM\Column(type="integer") */
  private $client_id;
  
  /** @ORM\Column(type="date") */
  private $date;
  
  /**
   * **
   * @ORM\ManyToMany(targetEntity="TreatmentType")
   * @ORM\JoinTable(name="session_treatments",
   *      joinColumns={@ORM\JoinColumn(name="session_id", referencedColumnName="id")},
   *      inverseJoinColumns={@ORM\JoinColumn(name="treatment_type_id", referencedColumnName="id ", unique=true)}
   *      )
   */
  private $session_treatments;
  
  /**
   * Constructor
   */
  public function __construct()
  {
      $this-&gt;session_treatments = new ArrayCollection();
  }
  }
  </code></pre>
  
  <p>Crm\ClientBundle\TreatmentType.php:</p>
  
  <pre><code>/**
   * @ORM\Entity
   * @ORM\Table(name="treatment_types")
   */
  class TreatmentType {
  
  /**
   * @ORM\Id
   * @ORM\Column(type="integer")
   * @ORM\GeneratedValue(strategy="AUTO")
   */
  private $id;
  
  /** @ORM\Column(type="string", length=255) */
  private $type;
  
  /** @ORM\Column(type="decimal") */
  private $cost;
  }
  </code></pre>