I have an Item. It belongs_to a User. I have an ItemSerializer and a UserSerializer in app/serializers:
class ItemSerializer < ActiveModel::Serializer
attributes :id, :photo
belongs_to :user
end
class UserSerializer < ActiveModel::Serializer
attributes :id, :email, :authentication_token
end
These relationships model the relationships in app/models
When I return an ActiverRecord::Relation of items as json in my controller:
def index
respond_to do |format|
@items = Item.where(id: params[:item_ids)
format.html
format.json { render json: @items, status: 200}
end
end
It should be returning the user attributes, including email and authentication_token, as well. But it is only returning the user id:
... "relationships":{"user":{"data":{"id":"1","type":"users"}}} ...
Why are the other user attributes not displaying?
@JohnMerlino2 I too have the same problem.Please post the solution if you have found it.
@indrapranesh this is not a bug
please see the docs
https://github.com/rails-api/active_model_serializers/blob/0-10-stable/docs/general/serializers.md
https://github.com/rails-api/active_model_serializers/blob/0-10-stable/docs/general/adapters.md#include-option
Most helpful comment
@indrapranesh this is not a bug
please see the docs
https://github.com/rails-api/active_model_serializers/blob/0-10-stable/docs/general/serializers.md
https://github.com/rails-api/active_model_serializers/blob/0-10-stable/docs/general/adapters.md#include-option