title: Symfony / Doctrine ManyToMany with conditions and limit
body: <p>I've created a concept of a Person model having many e-mails. I also have a Company model that can share the same e-mails with People (Person model).</p>
  
  <p>In short:
  People OneToMany PeopleEmail ManyToOne Email (classic manytomany unidirectional with a join table)</p>
  
  <pre><code>people { id, firstname, lastname, created }
  people_emails { person_id, email_id, main, created }
  emails { id, email, created }
  </code></pre>
  
  <p>as well as:</p>
  
  <pre><code>companies { id, name, employee_count, created }
  companies_emails { company_id, email_id, main, created }
  emails { id, email, created }
  </code></pre>
  
  <p>The problem is, that I'd like to store a boolean value called "main" in the join table as follows:</p>
  
  <pre><code>person_id | email_id | main | created
      8     |     5    | true | 2014-10-21 16:54:21
  </code></pre>
  
  <p>...so that I can do this:</p>
  
  <pre><code>Mark Wilson (Person) has 5 emails.
  3 of them are his company e-mails (shared): contact@company.com, office@company.com, it@company.com
  2 of them are his own.
  1 he answers only in his leisure time
  1 is his MAIN email: i.e. m.wilson@company.com
  </code></pre>
  
  <p>Instead of fetching all those 5 emails, I'd like to easily get the primary email just as if it was a regular Person model column:</p>
  
  <pre><code>firstname: Mark (string)
  lastname: Wilson (string)
  emails: (array)
  primary_email: (email object)
  </code></pre>
  
  <p>I cannot store the "main" property anywhere else, as I want to point, that the relation between Mark and his Email is "main", not the email itself.</p>
  
  <p>Now, I do have this value stored, but the problem is, how to make an entity property like:</p>
  
  <pre><code>class Person {
  
      (...)
  
      /**
       * @ORM\ManyToMany(targetEntity="Email")
       * @ORM\JoinTable(name="people_emails",
       *      joinColumns={@ORM\JoinColumn(name="person_id", referencedColumnName="id")},
       *      inverseJoinColumns={@ORM\JoinColumn(name="email_id", referencedColumnName="id", unique=true)}
       *      )
       */
      private $primary_email;
  
      /**
       * @ORM\ManyToMany(targetEntity="Email")
       * @ORM\JoinTable(name="people_emails",
       *      joinColumns={@ORM\JoinColumn(name="person_id", referencedColumnName="id")},
       *      inverseJoinColumns={@ORM\JoinColumn(name="email_id", referencedColumnName="id", unique=true)} // A condition?
       *      )
       */
      private $emails;
  
      public function getPrimaryEmail() {
          return $this-&gt;primary_email; // Single row limit?
      }
  
      public function getEmails() {
          return $this-&gt;emails;
      }
  
      (...)
  }
  </code></pre>
  
  <p>The thing is, I would really love to have it as an entity property, just for use in any case possible without the need to write custom repostory functions for the whole Person model.</p>
  
  <p>Or maybe that is a completely wrong way. I'd like to use that property in Twig like:</p>
  
  <pre><code>{{person.primary_email.email}}
  </code></pre>
  
  <p>To sum up:
  I'd like to store a ManyToMany single row relationship depending on joinTable column.</p>
  
  <p>How to do that?</p>