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

Handle correctly null associations #708

Merged
merged 1 commit into from
Oct 31, 2014
Merged

Handle correctly null associations #708

merged 1 commit into from
Oct 31, 2014

Conversation

guilleiguaran
Copy link
Member

null belongs_to associations are now serialized as nil instead
of raise an error during serialization.

null belongs_to associations are now serialized as nil instead
of raise an error during serialization.
@sogamoso
Copy link

👍

1 similar comment
@robertomiranda
Copy link

👍

@@ -133,7 +133,7 @@ def each_association(&block)
self.class._associations.dup.each do |name, options|
association = object.send(name)
serializer_class = ActiveModel::Serializer.serializer_for(association)
serializer = serializer_class.new(association)
serializer = serializer_class.new(association) if serializer_class
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a sanity check: if serializer is not defined, line 139 will throw undefined error, no? Shouldn't we raise here instead if serializer_class is nil?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, this doesn't throw an undefined error, instead serializer is nil in line 139

kurko added a commit that referenced this pull request Oct 31, 2014
Handle correctly null associations
@kurko kurko merged commit 462efc0 into rails-api:master Oct 31, 2014
@kurko kurko deleted the fix-for-nil-associations branch October 31, 2014 02:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants