Skip to content

Awkward to use association objects and association ids at the same time. #3

Closed
@ahawkins

Description

@ahawkins

I'm using this project in my application. I have classes that should return serialized objects and some that only only return the id's. At this point you can get around it by saying attributes :account_id then specifying has_one or has_many. I'm proposing a change to the API that would make it easier for this situation to work. Here is my proposed change:

class UserSerializer < ActiveModel::Serializer
  has_many :contacts, :embed => :objects
  belongs_to :account, :embed => :id
end

The embed method could set the preference, but I'm not sure how that would work. I am interested in adding this functionality and will gladly write a pull request if you guys thing this is a good thing to do.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions