Using ActiveModel::Serializer
(0.10.0.rc3) using the json-api
adapter, how can I render relationships with id only by default?
Consider my serializer
class ASerializer < Api::V1::BaseSerializer
attributes :id, :name
has_many :bs
end
However, that renders all the attributes defined in BSerializer
, too. I could define a BMiniSerializer
to only render the id
, and use it as
has_many :bs, serializer: BMiniSerializer
, but that means I'd have to do it for all Models and add it to all Serializers. Is there a more elegant, default way?
Edit
I suppose this is what :include
and :fields
are for. Unfortunately it seems that -- since I'm using a different namespace for my API-controllers and serializers from my model I need to specify the serializers for the associated models explicitly for :include
and :fields
to work.