I have a course model with 2 associations with another model, Tree:
belongs_to :interaction_outline, :class_name => "Tree", :foreign_key => "interaction_outline_id" belongs_to :token_outline, :class_name => "Tree", :foreign_key => "token_outline_id"
I read this and was able to include sisters associations in my controller.
@course.to_json(:include=> [:interaction_outline, :token_outline]
I also managed to get multiple nested associations:
@course.to_json(:include=>{:interaction_outline=> {:include=> {:tree_node=> {:include=> :definition}}}} )
BUT I can not get both brothers and repeatedly nested includes:
@course.to_json (:include=> [{:interaction_outline=> {:include=> {:tree_node=> {:include=> :definition}}}}, {:token_outline=> {:include=> {:tree_node=> {:include=> :definition}}}} ] )
I tried this too:
@course.to_json (:include=> [:interaction_outline=> {:include=> {:tree_node=> {:include=> :definition}}}, :token_outline=> {:include=> {:tree_node=> {:include=> :definition}}} ] )
What is the correct syntax here?
json ruby-on-rails activerecord
Matt garland
source share