This project is archived and is in readonly mode.

#5844 ✓stale
Nirmit Patel

ActiveRecord::Base.include_root_in_json only applies to root model and not to collection/children of that model..

Reported by Nirmit Patel | October 20th, 2010 @ 01:46 AM

This may or may not be an issue but I would like to have clarification. Both Rails 3.0 and edge rails behave similarly when providing the ActiveRecord::Base.include_root_in_json = true setting when rendering an active record model with includes.

The behavior I am describing is as follows when ActiveRecord::Base.include_root_in_json = true:


{"account": {"id":"123","users":[{"id":1},{"id":2},{"id":3}]}}
Expected (thought the way it should behave):
{"account": {"id":"123","users":[{"user":{"id":1}},{"user":{"id":2}},{"user":{"id":3}}]}}

I have been able to get this to work by monkey patching my current code but I don't want to implement something that is not a standard.

So if someone from the rails team could describe why the children collection models aren't rooted with the model name as well that would help me choose the correct implementation path. Bare in mind also that the xml serialization does have "user" nodes per users. That may be because json and xml are inherently different, but clarification would definitely help.

If the outcome is that this behavior needs to be changed I can submit a patch.


Nirmit Patel

Comments and changes to this ticket

  • Santiago Pastorino

    Santiago Pastorino February 2nd, 2011 @ 04:28 PM

    • State changed from “new” to “open”
    • Tag changed from activerecord json, rails 3.0, rails edge, json to activerecord json, rails 30, rails edge, json

    This issue has been automatically marked as stale because it has not been commented on for at least three months.

    The resources of the Rails core team are limited, and so we are asking for your help. If you can still reproduce this error on the 3-0-stable branch or on master, please reply with all of the information you have about it and add "[state:open]" to your comment. This will reopen the ticket for review. Likewise, if you feel that this is a very important feature for Rails to include, please reply with your explanation so we can consider it.

    Thank you for all your contributions, and we hope you will understand this step to focus our efforts where they are most helpful.

  • Santiago Pastorino

    Santiago Pastorino February 2nd, 2011 @ 04:28 PM

    • State changed from “open” to “stale”

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href=""></a>

People watching this ticket