Skip to content

Conversation

plexus
Copy link
Contributor

@plexus plexus commented Nov 11, 2013

When an Association detects that it is serializing an array, it calls use_array_serializer! to set the serializer to ArraySerializer, and set @options[:each_serializer] to the current serializer.

When use_array_serializer! is called a second time, :each_serializer is now ArraySerializer which causes things to blow up.

The symptom is "Undefined method `map'", since the ArraySerializer tries to iterate over a single object.

The HasMany association already contained a check to prevent calling use_array_serializer! twice, this PR adds a similar check to HasOne.

@samwgoldman
Copy link

I ran into this issue and this PR fixes the issue for me.

@plexus
Copy link
Contributor Author

plexus commented Dec 1, 2013

I realize my explanation it not very clear, but the code is quite straightforward. Should I supply more info? Feeback would be appreciated!

@plexus
Copy link
Contributor Author

plexus commented Dec 9, 2013

Closes #456

spastorino added a commit that referenced this pull request Dec 17, 2013
Using a HasOne association twice raises an exception (Undefined method `map')
@spastorino spastorino merged commit 80d9fb5 into rails-api:master Dec 17, 2013
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.

3 participants