I am working on an RoR project with ruby-2.5.0 and rails 5. I am using the jsonapi-serializers
for my API. I want to customize the attributes of the associated model. I have two models Receipt and ReceiptPartial
. receipt has_many :receipt_partials
. when I write has_many :receipt_partials
in my serializer it returns all the columns but I want only a few columns.
class ReceiptPartialSerializer
include JSONAPI::Serializer
TYPE = 'receipt'
attribute :id
has_many :receipt_partials
end
I want to restrict the columns of receipt_partials.
I also tried has_many :receipt_partials, only: ['id']
but didnot work.
How can I achieve this? Please help. Thanks in advance.