# Combining associated models into a single xml or json object

**URL:** <https://www.ruby-forum.com/t/combining-associated-models-into-a-single-xml-or-json-object/139429>\
**Category:** Rails\
**Created:** [June 3, 2008, 8:59pm UTC](https://www.ruby-forum.com/t/combining-associated-models-into-a-single-xml-or-json-object/139429 "2008-06-03T20:59:28Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jkahn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/53a042/32.png) [@jkahn](https://www.ruby-forum.com/u/jkahn)\
**Post date:** [June 3, 2008, 8:59pm UTC](https://www.ruby-forum.com/t/combining-associated-models-into-a-single-xml-or-json-object/139429/1 "2008-06-03T20:59:28Z")

</div>

It is clear how to return a model with model.to\_json or model.to\_xml.  
But how does one returned an object that with associations included?  
I thought the following would work but it seems to only return the  
base model.

folder = Folder.find\_by\_id(7, :include =\> [permissions])

respond\_to do |f|  
…  
f.json { render :json =\> folder.to\_json}  
end

Thanks,  
j

---

<div class="post-metadata">

**Author:** ![jkahn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/53a042/32.png) [@jkahn](https://www.ruby-forum.com/u/jkahn)\
**Post date:** [June 3, 2008, 9:51pm UTC](https://www.ruby-forum.com/t/combining-associated-models-into-a-single-xml-or-json-object/139429/2 "2008-06-03T21:51:00Z")

</div>

No sooner do I post than I realize my mistake.

(:include is the message to .to\_json, not ‘find’)

i.e.

f.json { render :json =\> folder.to\_json(:include=\> [permissions]) }

Thanks,  
j
