Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

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

#5844

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:

Currently:

{"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.

Thanks,

Nirmit Patel

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

State: stale
Milestone: none
Assigned to: nobody
Importance: none

Activity

  1. Santiago Pastorino
    Santiago Pastorino
    • 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.

    February 2nd, 2011 @ 04:28 PM

  2. Santiago Pastorino
    Santiago Pastorino
    • State changed from open to stale

    February 2nd, 2011 @ 04:28 PM