title: How to sort records by relation field using relation fields column in Doctrine?
body: <p>I have 2 entities in relation ManyToOne. ScheduledEvent and Tariff entites. </p>
  
  <p>First entity is ScheduledEvent with field tariff where tariff is ManyToOne relation. And I have configured it like this in ScheduledEvent entity:</p>
  
  <pre><code> /**
   *
   * @ORM\ManyToOne(targetEntity="Tariff", inversedBy="scheduledEvents")
   * @ORM\JoinColumn(name="tariff_id", referencedColumnName="id")
   **/
  private $tariff;
  </code></pre>
  
  <p>And Tariff entity that has 'name' and 'scheduledEvents' fields set up like this:</p>
  
  <pre><code>/**
   * @var string
   *
   * @ORM\Column(name="name", type="string", length=255)
   */
  private $name;
  
  
  /**
  *
  * @ORM\OneToMany(targetEntity="ScheduledEvent", mappedBy="tariff")
  */
  private $scheduledEvents;
  </code></pre>
  
  <p>Is it possible to configure ScheduledEvent entity in annotaion or some other way so that when I select records from ScheduledEvent entity I sort by Tariffs name column.</p>
  
  <p>So for example when I build query like this:</p>
  
  <pre><code>$repository = $em-&gt;getRepository('SMAPIBundle:ScheduledEvent');
  $repository-&gt;createQueryBuilder('sce')
         -&gt;setFirstResult(0)
         -&gt;setMaxResults(10)
         -&gt;orderBy('sce.tariff', $sortColumnOrder);
  </code></pre>
  
  <p>I want to be able to tell him only to sort by tariff but configure it to sort by Tariff's name column instead of id when I sort ScheduledEvent records by tariff. </p>
  
  <p>Is this possible?</p>
  
  <p>I know where is OrderBy annotation:</p>
  
  <pre><code>/**
   *
   * @ORM\ManyToOne(targetEntity="Tariff", inversedBy="scheduledEvents")
   * @ORM\JoinColumn(name="tariff_id", referencedColumnName="id")
   * @ORM\OrderBy("name")
   **/
  private $tariff;
  </code></pre>
  
  <p>But that is only used for ManyToMany and OneToMany relations.</p>
  
  <p>So any ideas on how to sort by relation field using <strong>relation fields column</strong> when retrieving records for entity?</p>
  
  <p>I am using Doctrine 2.4.6.</p>