I like to use roda's :json plugin for sending JSON API Data where we just
send Array/Hash as output of a route. But, in order to take advantage of
Sequel Models and associations, I end up with arrays of models and
associated models.
For example:
plugin :json, :classes => [Array, Hash, Sequel::Model]
r.get "eager_test" do
jobs = Job.where(:id => [100254,100255]).eager(:job_items).all
@rs[:jobs] = jobs.map do |v|
h = v.to_hash
h[:job_items] = v.job_items.map {|ji| ji.to_hash}
h
end
@rs
end
This works as expected, but I am just wondering if there is a better way to
do it, without looping thru. Even though Sequel::Model is specified in
:json plugin options, it wouldn't convert Array of models to proper json
output, just pure models I guess.
Thanks
--
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.