require 'sequel'
DB = Sequel.sqlite
DB.create_table :artists do
primary_key :id
String :name
end
DB.create_table :albums do
primary_key :id
String :name
end
DB.create_table :artists_albums do
foreign_key :artist_id, :artists
foreign_key :album_id, :albums
end
DB[:artists].insert name: 'Artist Foo'
DB[:albums].insert name: "Foo's Album (Part 1)"
DB[:albums].insert name: "Foo's Album (Part 2)"
DB[:albums].insert name: "Foo's Album (Part 3)"
DB[:artists_albums].insert artist_id: 1, album_id: 1
DB[:artists_albums].insert artist_id: 1, album_id: 2
DB[:artists_albums].insert artist_id: 1, album_id: 3
Having these, which is the easiest way to obtain
{id: 1, name: "Artist Foo", albums: [{id: 1, name: "Foo's Album (Part
1)"}, {id: 2, name: "Foo's Album (Part 2)"}, {id: 3, name: "Foo's Album
(Part 3)"}]}
Sorry for my noobness!
TY!
--
You received this message because you are subscribed to the Google Groups
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.