Sorry to waste your time - I answered my own question. It needs to be eager
loaded:
author.eager(:books).all.map{|a| a.values.merge(:books=>a.books.map{|b| b.
values}) }.to_json
# returns
[
[0] {
"id" => 1,
"name" => "John le Carre",
"books" => [
[0] {
"id" => 1,
"title" => "Tinker Tailor Soldier Spy",
"author_id" => 1
},
[1] {
"id" => 2,
"title" => "The spy who came in from the cold",
"author_id" => 1
}
]
},
[1] {
"id" => 2,
"name" => "Leo Tolstoy",
"books" => [
[0] {
"id" => 3,
"title" => "War and Peace",
"author_id" => 2
}
]
}
]
Thanks anyway
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.