When using with :json_api adapter: the "attributes" key is not present for has_many-associated objects
When NOT specifying an adapter, it serializes an Account (that has_many Profiles) like this:
{
:id=>1,
:something=>"this",
:profiles=>[
{
:id=>1,
:name=>"Mike Miller"
},
{
:id=>2,
:name=>"Mike Miller"
}
]
}
Note that the :name attributes are present for each Profile. Now, when specifying the :json_api adapter, it returns
{
:data=>{
:id=>"1",
:type=>"accounts",
:attributes=>{
:something=>"this"
},
:relationships=>{
:profiles=>{
:data=>[
{
:id=>"1",
:type=>"profiles"
},
{
:id=>"2",
:type=>"profiles"
}
]
}
}
}
}
where the :name attributes and the whole "attributes" key is not present for each Profile.
Am I doing something wrong here or is this a bug?
I created an example application for this problem: https://github.com/esBeee/serializer_test_app It is using rails 4.2.4, active_model_serializers 0.10.0.rc4 and ruby 2.1.2.
you need to include the relationship. via the include option.
so:
render json: account, include: 'profiles'
Alright, that works! Thanks @NullVoxPopuli !