Description
module Fruit
module Banana
class SugarSerializer < ActiveModel::Serializer
has_one :molecule
end
end
end
module Fruit
module Banana
class MoleculeSerializer < ActiveModel::Serializer
...
end
end
end
class MoleculeSerializer < ActiveModel::Serializer
...
end
class SugarSerializer < ActiveModel::Serializer
has_one :molecule
end
In my opinion Fruit::Banana::SugarSerializer should serialize the molecule relationships (via include) with the Fruit::Banana::MoleculeSerializer instead of the global namespaced one. If Fruit::Banana::MoleculeSerializer did not exist then it would use the global namepsaced one, or if SugarSerializer was not namepsaced it would use the global namespaced molecule one. I realise I can work around this by explicitly setting the serializer on the relations but its a bit cumbersome.
Reading around http://guides.rubyonrails.org/association_basics.html section 3.4
Indicates:
To associate a model with a model in a different namespace, you must specify the complete class name in your association declaration:
module MyApplication
module Business
class Supplier < ActiveRecord::Base
has_one :account,
class_name: "MyApplication::Billing::Account"
end
end
module Billing
class Account < ActiveRecord::Base
belongs_to :supplier,
class_name: "MyApplication::Business::Supplier"
end
end
end
So I'm thinking this is not really a bug and I just have to bite the bullet and write all of the serializers in.