title: Kohana: How to load all many-to-many relationships in one query
body: <p>I have a database relationship that looks something like this:</p>
  
  <pre><code>booking -&gt; person &lt;-&gt; option
  
  -&gt;  : one-to-many
  &lt;-&gt; : many-to-many
  </code></pre>
  
  <p>I now need to list all the persons in a booking, with all their options. Using ORM in kohana I can load all persons like this:</p>
  
  <pre><code>$persons = ORM::factory('booking', $id)-&gt;persons-&gt;find_all();
  </code></pre>
  
  <p>I could then loop over the persons and get all their options, but that would mean one query per person. Is there a clever way to load this without having to do that? What I would like to end up with is something like this:</p>
  
  <pre><code>booking
   └ id
   └ created
   └ persons
      └ 0
        └ id
        └ name
        └ options
           └ 0
             └ id
             └ price
           └ n
             └ id
             └ price
      └ n
        └ id
        └ name
           └ options
           └ 0
             └ id
             └ price
           └ n
             └ id
             └ price
  </code></pre>
  
  <p>I probably have to write a custom database query for this, but even then I am not quite sure how to do it. My SQL-fu isn't the best :p</p>