To be more precise, simple models work, what doesn't work are Eager models.
@rs[:jobs] = Job.where(:id => [100,101]).eager(:job_items).all I get the jobs, but not the job_items. Thanks. On Monday, 20 April 2020 09:39:33 UTC-6, shreko wrote: > > Yes, in models.rb I have a line > > Sequel::Model.plugin :json_serializer > > > but this doesn't solve my issue. > > Thanks. > > > On Monday, 20 April 2020 09:15:07 UTC-6, Jeremy Evans wrote: >> >> On Monday, April 20, 2020 at 7:17:27 AM UTC-7, shreko wrote: >>> >>> Sorry for pulling out a two year old question (Best way to Serialize >>> Models <https://groups.google.com/forum/#!topic/sequel-talk/o2vVW2tURXw>), >>> but there is a piece of a puzzle still missing for me and I still don't >>> know how to do what I would like to: >>> >>> # Using roda's :json plugin >>> plugin :json, classes => [Array, Hash, Sequel::Model] >>> >>> >>> # In the main route start collecting different things in a hash @rs that >>> we be sent to the client as JSON at the end >>> route do |r| >>> @rs = {} >>> >>> # user record, this is DB persisted session >>> @rs[:user] = current_user(r.cookies('SESSIONID')) >>> >>> # Maybe some other record that will be sent on every request >>> @rs[:user_settings] = user_settings(@rs[:user][:id]) >>> >>> r.multi_route >>> end >>> >>> >>> # in the multi_route branch >>> r.get "jobs" do >>> >>> @rs[:jobs] = Job.where(:id => [100,101]).eager(:job_items).all >>> >>> # and the last statement of every route would be @rs which will be >>> converted to JSON by roda's :json plugin >>> # this pattern works great when @rs hash values are arrays and >>> hashes, but Models in the mix don't work) >>> >>> @rs >>> >>> end >>> >>> >>> >>> >> Are you using the Sequel json_serializer plugin in your models? If not, >> you probably should. I assume that will fix your issue, as the Roda json >> plugin just calls to_json on the resulting object, and the Sequel >> json_serializer plugin adds Model#to_json. >> >> Thanks, >> Jeremy >> > -- 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 view this discussion on the web visit https://groups.google.com/d/msgid/sequel-talk/8f8d7550-31d7-4bd7-80ea-7c335d55ee7c%40googlegroups.com.
