Many thanks. Dynamically creating the models works well, but can I ask a 
supplementary?

Look at these results:

carre = author.create(name: 'John le Carre')
tolstoy = author.create(name: 'Leo Tolstoy')
book.create(title: 'Tinker Tailor Soldier Spy', author_id: carre.id)
book.create(title: 'The spy who came in from the cold', author_id: carre.id)
book.create(title: 'War and Peace', author_id: tolstoy.id)

author.first.to_json( :include => { :books => { :only => :id } } )
# returns:
{
     "id" => 1,
     "name" => "John le Carre",
     "books" => [
     [0] {
         "json" => "{\"id\":1}"
     },
     [1] {
         "json" => "{\"id\":2}"
        }
    ]
}

author.all.to_json( :include => { :books => { :only => :id } } )
# returns
[
    [0] {
           "id" => 1,
           "name" => "John le Carre",
    },
    [1] {
           "id" => 2,
           "name" => "Leo Tolstoy",
    }
]


So association does not work on an array of results.


Is that normal?


Thanks again

Nick

-- 
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 https://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.

Reply via email to