title: How to include nested and sibling associations in active record to_json?
body: <p>I have a Course model with 2 associations to another model, Tree:</p>
  
  <pre><code>belongs_to  :interaction_outline, :class_name =&gt; "Tree", 
                                    :foreign_key =&gt; "interaction_outline_id"
  belongs_to  :token_outline, :class_name =&gt; "Tree", 
                                    :foreign_key =&gt; "token_outline_id"
  </code></pre>
  
  <p>I read <a href="http://apidock.com/rails/ActiveRecord/Serialization/to_json">this</a> and was able to include sibling associations in my controller.</p>
  
  <pre><code>@course.to_json(:include=&gt; [:interaction_outline, :token_outline]
  </code></pre>
  
  <p>I was also able to get multiply nested associations:</p>
  
  <pre><code>@course.to_json(:include=&gt;{:interaction_outline=&gt; 
                                {:include=&gt; {:tree_node=&gt; 
                                       {:include=&gt; :definition}}}} )  
  </code></pre>
  
  <p>BUT I cannot get both sibling AND multiply nested includes:</p>
  
  <pre><code>@course.to_json (:include=&gt; [{:interaction_outline=&gt; 
                                 {:include=&gt; {:tree_node=&gt; 
                                      {:include=&gt; :definition}}}}, 
                              {:token_outline=&gt; 
                                 {:include=&gt; {:tree_node=&gt; 
                                     {:include=&gt; :definition}}}} ] ) 
  #NoMethodError (undefined method `macro' for nil:NilClass)
  #the error you get when the syntax or the association is wrong
  </code></pre>
  
  <p>I tried this, too:</p>
  
  <pre><code>@course.to_json (:include=&gt; [:interaction_outline=&gt; 
                                 {:include=&gt; {:tree_node=&gt; 
                                     {:include=&gt; :definition}}}, 
                            :token_outline=&gt; 
                               {:include=&gt; {:tree_node=&gt; 
                                      {:include=&gt; :definition}}} ] ) 
  #same error
  </code></pre>
  
  <p>What is the right syntax here? </p>