Skip to content

to_json includes do not output multiple associations, only the first if any have additional parameters #9500

@antoinne85

Description

@antoinne85

When you attempt to ":include" multiple associated records in a call to to_json, only the first association is included if you specify further inclusions for that association.

For example:

render :json => video.to_json(
      :include => {:fight_sets => {
          :include => [:fight_matches => {:include => [:player_one_team, :player_two_team]}, :player_one => {}, :player_two => {}]}});

the json will include all of the fight_matches, but will not include either player_one or player_two.

If instead, you swap :fight_matches with :player_one, giving you

render :json => video.to_json(
      :include => {:fight_sets => {
          :include => [:player_one => {}, :fight_matches => {:include => [:player_one_team, :player_two_team]}, :player_two => {}]}});

the json will include player_one but not fight_matches or player_two.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions