thanks for response

THis here would produce syntax error:

:include => {:reports, :notifications => :notification_codes}

So I try this (to ensure :reports has a value):

{:include => {:reports => {}, :notifications => :notification_codes}}

And this is ultimately what it would look like:

User.where(:id => params[:user_id]).first.units.to_json({:include =>
{:reports => {}, :notifications => :notification_codes}})

But this will say:

can't convert Symbol into Hash

On Nov 16, 3:14 am, Frederick Cheung wrote:
On Nov 15, 11:06 pm, John Merlino wrote:

this error usually occurs when trying to mix 1st and 2nd order
relationships in a single to_json call:
undefined method `macro' for nil:NilClass
Rails 3 has this way to support 2nd order relationships:
So I try to use it:
@units = User.where(:id =>
params[:user_id]).first.units.to_json(:include => {
:only => :reports,
:notifications => {:include => {:only
=> :notification_codes} }
A unit has many reports and notifications. And a notification belongs
to notification code.
There is an example of second order include & only on the page you
link to. You're using :only to refer to association names whereas only
is supposed to denote which attributes you want to show for a given
object so i think you are confusing to_json. something like :include
=> {:reports, :notifications => :notification_codes} should do the


:include => {:notifications, :only => :reports, :include => {:

This is the relationship between notifications and notification codes:
belongs_to :notification_code, :foreign_key => :code
//notification codes
has_many :notifications
So I am not sure why error occurs.
Thanks for response
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to
To unsubscribe from this group, send email to
For more options, visit this group at

Search Discussions

Discussion Posts


Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 5 of 7 | next ›
Discussion Overview
grouprubyonrails-talk @
postedNov 15, '11 at 11:19p
activeNov 18, '11 at 3:09p



site design / logo © 2021 Grokbase