Open
Description
Using rails 4, I have a domain object with a Serializer
class DomainObject < ActiveRecord::Base
...
end
class DomainObjectSerializer < ActiveModel::Serializer
attributes :attr1, :attr2, :attr3
has_many :foos
has_many :bars
end
Using active_model_serializer v0.9.4 I could do
record = DomainObject.find(..)
serializer = DomainObjectSerializer.new(record, root: false, except: [:foos])
serializer.to_json
to get a JSON-String containing all the attributes and the association :bars
, but not the association :foos
.
After switching to active_model_serializer v0.10.2 this does not work anymore. The string contains all attributes. It seems, like the following gives me the same output:
record = DomainObject.find(..)
serializer = DomainObjectSerializer.new(record)
serializer.to_hash.to_json(except: [:foos])
But as the to_json
call typically is done in the view layer, while the serializer is build inside a model or service, it seems not to be a good solution. Did I miss some configuration option?