Nested model json

16 views
Skip to first unread message

Avi

unread,
Feb 6, 2013, 12:24:24 AM2/6/13
to rubyonra...@googlegroups.com
Hello All,

I have model relationship as :-

users has_many sub_users
sub_users has_many address

How can I do a nested json call?
I am getting sub_users value. How can I get address values through json? I want all the 3 datas(users, sub_users_address at a time)

For single nested I tried - respond_with @users.to_json(:include => [:sub_users])

Thanks,
Avi
 

Avi

unread,
Feb 6, 2013, 1:42:29 AM2/6/13
to rubyonra...@googlegroups.com
Ok found the solution:-
respond_with(@users,  :include => {:sub_users => {:include => [:address]}})

Thanks..
Reply all
Reply to author
Forward
0 new messages