On Wednesday, March 7, 2012 2:33:17 AM UTC-8, kavkaz wrote:
>
> Below is a sample script and exit. 
> Two typical models, cities and countries. Need to get json data from 
> all the cities of the country involved. 
> According to the documentation (http://sequel.rubyforge.org/rdoc- 
> plugins/classes/Sequel/Plugins/JsonSerializer.html<http://sequel.rubyforge.org/rdoc-plugins/classes/Sequel/Plugins/JsonSerializer.html>),
>  
> the output should 
> be JSON with nested structures. But in this example, the output array 
> of hashes, not attachments. This is the correct behavior of the plug- 
> in serializer? 
>
 
The reason your code doesn't work is that you are calling to_json on an 
Array of objects, not on a Dataset, and the JSON library doesn't pass 
arguments given to Array#to_json to the elements.  You can fix your code by 
doing:

  puts City.eager_graph(:country).to_json(:include => :country)

Jeremy

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/sequel-talk/-/auK3Fdk_PF4J.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sequel-talk?hl=en.

Reply via email to