On Monday, July 2, 2012 6:42:25 AM UTC-7, natedooggg wrote:
>
> Hi,
>
> Im hoping some one can help me out here with an association issue im 
> having.
>
> I have a movie model which has many scenes
>
> i output the movie instance to json and xml in my sinatra app, but im 
> having trouble returning the nested scene objects.
>
> i want to have output like this
>
> { "move": { "name":"example",
>                   "scenes": [ {"scene": {"name": "scene 1" } },
>                                     {"scene": {"name": "scene 1" } },  
>                                    {"scene": {"name": "scene 1" } }, 
>                                   {"scene": {"name": "scene 1" } }
>                                   ]  
>  }
>
> ive tried to attempt this via eager loading, but having no luck.
>
> In my sinatra  app call im loading the movie instance with
>
> @movie = Movie.find(:id=>params[:id]) 
>
> I was looking to create a method on my model and put the list of scene 
> objects into an attribute call scene list.. but this started to feel like 
> ive missed something obvious.
>
> aplogies if the answer is somewhere in the docs and i ve overlooked it .
>

You probably want:

  @movie.to_json(:include=>{:scenes=>{:naked=>true, :root=>true}}, 
:naked=>true, :root=>true)

Thanks,
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/-/JmUsg1oTJRQJ.
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