I have the following serializers:
class V1::CategorySerializer < ActiveModel::Serializer
has_one :category_name, :class_name => 'V1::CategoryName'
has_many :brands, :class_name => 'V1::Brand'
end
class V1::CategoryNameSerializer < ActiveModel::Serializer
attributes :name
has_many :brand_names, :class_name => 'V1::BrandName'
end
class V1::BrandSerializer < ActiveModel::Serializer
has_one :brand_name, :class_name => 'V1::BrandName'
end
class V1::BrandNameSerializer < ActiveModel::Serializer
attributes :name
end
When I render via Category render json: seller.categories
I do not want the BrandNames to be printed. Output should be something like:
{
"seller_id": 1,
"categories" :
[
{
"name" : "Washing Machines",
"brands" : ["LG", "Samsung"]
}
]
}
instead of
{
"brands_categories": [
{
"category_name": {
"name": "Washing Machines",
"brand_names": [
{
"name": "LG"
},
{
"name": "Samsung"
}
]
},
"brands": [
{
"brand_name": {
"name": "LG"
}
},
{
"brand_name": {
"name": "Samsung"
}
}
]
}
]
}
Also, I want to keep the current behavior of printing render json: V1::CategoryName.all
as it is.