From: Jeremy Evans Date: 2010-02-19T09:53:12+09:00 Subject: Re: Convert Sequel Dataset to JSON Object Phil Tayo wrote: > Jeremy Evans wrote: >> FYI, a Sequel dataset is an abstract representation of an SQL query, it >> doesn't contain any records itself. Assuming that Array#to_json works >> correctly, you could define: >> >> class Sequel::Dataset >> def to_json >> all.to_json >> end >> end >> >> and then call to_json on a dataset to get the query results in JSON >> format. > > Thanks for that. A couple of problems I still have though: > > 1. I tried: > ... > Task.all.to_json > ... > and ".all" still returned an array of object references without the > actual values, like this: > > ["#","#","#","#","#","#","#"] > > 2. Once that's working, where should I put this code: >> class Sequel::Dataset >> def to_json >> all.to_json >> end >> end > Can you point me in the direction of any useful reading material? If your dataset is a model dataset, you probably don't want model objects. Try this more general version: class Sequel::Dataset def to_json naked.all.to_json end end The naked part means that instead of model objects, plain hashes are returned. Jeremy -- Posted via http://www.ruby-forum.com/.