How can I build a collection from two pre-serialized collections? In other words, I want to do something like this:
class ItemSerializer < ActiveModel::Serializer
attributes :items
has_many :things, :serializer => ThingSerializer
has_many :other_things, :serializer => OtherThingSerializer
def items
things + other_things
end
def things
object.things.where(:this => 'that')
end
def other_things
object.other_things.where(:that => 'this')
end
end
However, this does not work-- The individual serializers are not used.. The only way I can make this work is to do:
class ItemSerializer < ActiveModel::Serializer
attributes :items
def items
things + other_things
end
def things
object.things.where(:this => 'that').map do |thing|
ThingSerializer.new(thing, options)
end
end
def other_things
object.other_things.where(:that => 'this').map do |other_thing|
OtherThingSerializer.new(other_thing, options)
end
end
end
Which I would really like to avoid...