Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

key attribute being ignored on associations in 0.9.0 #670

Closed
shedd opened this issue Oct 1, 2014 · 4 comments
Closed

key attribute being ignored on associations in 0.9.0 #670

shedd opened this issue Oct 1, 2014 · 4 comments
Labels

Comments

@shedd
Copy link

shedd commented Oct 1, 2014

In version 0.8.x we were using the key attribute for has_one relationships like the following:

has_one :user, serializer: Api::V1::UserSerializer, key: :user_assigned

This seems to have broken in 0.9.0.

The record comes through with the key user rather than user_assigned

I've downgraded back to 0.8.2 and this works as expected again.

@azuby
Copy link

azuby commented Oct 2, 2014

@shedd I was able to dig this out of the compare between 0.8 and 0.9: https://github.com/rails-api/active_model_serializers/compare/0-8-stable...0-9-stable?diff=unified#diff-04c6e90faac2675aa89e2176d2eec7d8R436

I tested using the root attribute instead of key and it works for me. Is there anywhere in the current docs where it says to still use key? If so, it should be updated. If not, I think this could be added.

@steveklabnik Is root going to be a permanent replacement for the key attribute?

@shedd
Copy link
Author

shedd commented Oct 3, 2014

@Retistic thanks! changing key to root does indeed seem to work.

For 0.10.x, how should we be thinking about these changes, given this statement in the README: "0.10.x will be based on the 0.8.0 code"

How many of the 0.9.x changes will be adopted for 0.10.x?

Regarding the docs, I still see key in use in these examples in the 0.9.x README:

class PostSerializer < ActiveModel::Serializer
  attributes :id, :title, :body

  has_many :comments, embed: :ids, key: :comments, embed_namespace: :links
end
class PostSerializer < ActiveModel::Serializer
  embed :ids, include: true

  attributes :id, :title, :body
  has_many :comments, key: :comment_ids, root: :comment_objects
end
class PostSerializer < ActiveModel::Serializer
  embed :ids, include: true

  attributes :id, :title, :body
  has_many :comments, key: :external_id
end

@klippx
Copy link

klippx commented Oct 20, 2014

+1 same issue here. Should root be used instead of key? Comment from authors?

@steveklabnik
Copy link
Contributor

0.10 is going to follow 0.8, not 0.9, so I would expect this to be fixed there. 0.9 is sorta its own thing, a dead end.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants