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

Fixed a bug that appeared when json adapter serialize a nil association #892

Merged
merged 1 commit into from
May 5, 2015

Conversation

groyoh
Copy link
Member

@groyoh groyoh commented Apr 28, 2015

Take the following serializers e.g.:

AuthorPreviewSerializer = Class.new(ActiveModel::Serializer) do
  attributes :id, :name
end    
PostPreviewSerializer = Class.new(ActiveModel::Serializer) do
  attribute :id
  # note that we specify a serializer for the association
  belongs_to :author, serializer: AuthorPreviewSerializer
end

If a post is serialized with Json adapter and its author is nil, then the post would be rendered as :

{ 
  id: 43, 
  author: { id: nil, name: nil }
}

instead of

{ 
  id: 43, 
  author: nil
}

This happens only when the serializer option is set for the association.

@philipgiuliani
Copy link

Thanks a lot! I just ran into this. Would be cool to get it merged!

@joaomdmoura
Copy link
Member

Tks @groyoh ! I'm merging it 👍

joaomdmoura added a commit that referenced this pull request May 5, 2015
Fixed a bug that appeared when json adapter serialize a nil association
@joaomdmoura joaomdmoura merged commit ece43f3 into rails-api:master May 5, 2015
@groyoh groyoh deleted the fix-json-nil-association branch May 18, 2015 14:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants