title: Retrieving nested records in Sequel
body: <p>I'm trying to retrieve data in a nested form from the following two tables (in SQLite)</p>
  
  <pre><code>DB = Sequel.sqlite('database.sqlite')
  
  DB.create_table? :artists do
      primary_key     :id
      String          :name
  end
  
  DB.create_table? :albums do
      primary_key     :id
      String          :title
      foreign_key     :artist_id,
                      :artists,
                      :key =&gt; :id
  end
  
  artists = DB[:artists]
  albums = DB[:albums]
  
  id1 = artists.insert(:name =&gt; 'Mike')
  id2 = artists.insert(:name =&gt; 'John')
  
  albums.insert(:title =&gt; 'Only You', :artist_id =&gt; id1 )
  albums.insert(:title =&gt; 'Only Us', :artist_id =&gt; id1 )
  albums.insert(:title =&gt; 'Only Me', :artist_id =&gt; id2 )
  </code></pre>
  
  <p>The output I'm trying to get -</p>
  
  <pre><code>[
    {
      :id =&gt; 1,
      :name =&gt; 'Mike'
      :albums =&gt; [
        {
          :id =&gt; 1,
          :title =&gt; 'Only You'
        },
        {
          :id =&gt; 2,
          :title =&gt; 'Only Us'
        }
      ]
    },
    {
      :id =&gt; 2,
      :name =&gt; 'John'
      :albums =&gt; [
        {
          :id =&gt; 3,
          :title =&gt; 'Only Me'
        }
      ]
    }
  ]
  </code></pre>
  
  <p>I've tried 'eager' loading -</p>
  
  <pre><code>class Artist &lt; Sequel::Model(:artists)
    one_to_many  :db[:albums], :key =&gt; :artist_id
  end
  
  class Album &lt; Sequel::Model(:albums)
    many_to_one  :artist, :key =&gt; :artist_id
  end
  
  
  Artist.eager(:albums).all{ |a| p a }
  </code></pre>
  
  <p>But that didn't work.</p>
  
  <p>Can anyone point me in the right direction?</p>