You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
@JohnMerlino2 that's how the JSON:API spec works. I'm guessing you're on 0.10.x and using JSON:APi. Take a look at included relationships to get what you're talking about.
I have an Item. It belongs_to a User. I have an ItemSerializer and a UserSerializer in app/serializers:
These relationships model the relationships in app/models
When I return an ActiverRecord::Relation of items as json in my controller:
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?
The text was updated successfully, but these errors were encountered: