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

[0.10.0rc1] has_many doesn't work without serializer defined on association #877

Closed
JustinAiken opened this issue Apr 22, 2015 · 7 comments · Fixed by #962
Closed

[0.10.0rc1] has_many doesn't work without serializer defined on association #877

JustinAiken opened this issue Apr 22, 2015 · 7 comments · Fixed by #962

Comments

@JustinAiken
Copy link
Contributor

I have this serializer:

class BrandSerializer < ActiveModel::Serializer
  attributes ...

  ...
  has_many :style_configurations
...
end

style_configurations doesn't have an AMS defined, it's just using the standard rails json response. Under 0.9x this works fine, but on today's new RC, I get this:

     NoMethodError:
       undefined method `new' for nil:NilClass
     # /Users/jaiken/.rvm/gems/ruby-2.2.1/gems/active_model_serializers-0.10.0.rc1/lib/active_model/serializer/array_serializer.rb:17:in `block in initialize'
     # /Users/jaiken/.rvm/gems/ruby-2.2.1/gems/activerecord-4.2.1/lib/active_record/relation/delegation.rb:46:in `map'
     # /Users/jaiken/.rvm/gems/ruby-2.2.1/gems/activerecord-4.2.1/lib/active_record/relation/delegation.rb:46:in `map'
     # /Users/jaiken/.rvm/gems/ruby-2.2.1/gems/active_model_serializers-0.10.0.rc1/lib/active_model/serializer/array_serializer.rb:12:in `initialize'
     # /Users/jaiken/.rvm/gems/ruby-2.2.1/gems/active_model_serializers-0.10.0.rc1/lib/active_model/serializer.rb:215:in `new'
     # /Users/jaiken/.rvm/gems/ruby-2.2.1/gems/active_model_serializers-0.10.0.rc1/lib/active_model/serializer.rb:215:in `block in each_association'
     # /Users/jaiken/.rvm/gems/ruby-2.2.1/gems/active_model_serializers-0.10.0.rc1/lib/active_model/serializer.rb:208:in `each'
     # /Users/jaiken/.rvm/gems/ruby-2.2.1/gems/active_model_serializers-0.10.0.rc1/lib/active_model/serializer.rb:208:in `each_association'
     # /Users/jaiken/.rvm/gems/ruby-2.2.1/gems/active_model_serializers-0.10.0.rc1/lib/active_model/serializer/adapter/json.rb:17:in `serializable_hash'
     # /Users/jaiken/.rvm/gems/ruby-2.2.1/gems/active_model_serializers-0.10.0.rc1/lib/active_model/serializer/adapter.rb:23:in `as_json'
     # /Users/jaiken/.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.1/lib/active_support/json/encoding.rb:34:in `encode'
     # /Users/jaiken/.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.1/lib/active_support/json/encoding.rb:21:in `encode'
     # /Users/jaiken/.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.1/lib/active_support/core_ext/object/json.rb:37:in `to_json_with_active_support_encoder'
     # /Users/jaiken/.rvm/gems/ruby-2.2.1/gems/actionpack-4.2.1/lib/action_controller/metal/renderers.rb:116:in `block in <module:Renderers>'
     # /Users/jaiken/.rvm/gems/ruby-2.2.1/gems/active_model_serializers-0.10.0.rc1/lib/action_controller/serialization.rb:49:in `block (2 levels) in <module:Serialization>'
@kurko kurko added this to the 0.10 milestone Apr 22, 2015
@CV-Gate
Copy link

CV-Gate commented Apr 23, 2015

Same here, I avoided that error specifying a serializer for the relationship.

@bf4
Copy link
Member

bf4 commented Apr 25, 2015

Duplicate of #870

@JustinAiken
Copy link
Contributor Author

I think it's similar symptoms, but not a dup of #870...

  • Problem with each_serializer: foo and has_many associations #870 deals more with when the serializer for the has_many does exist, but the options hash for getting the association isn't passing through okay..
  • This one is for when the child serializer doesn't exist at all. In previous versions of AMS, if you have a Foo model and a Bar model, and the FooSerializer has_many :bars, but there's no BarSerializer at all, it would just stick the standard rails build-in serialization to populate the the bars field... now it tosses up that error.

@joaomdmoura
Copy link
Member

I'm also not sure if it's a dup. Not sure if #949 impacts it.
Would be awesome to have a PR with a falling test on this one 😄 @JustinAiken would you be able to do this?

@bf4
Copy link
Member

bf4 commented Jun 12, 2015

I think this is related to #945 (comment) as well

@JustinAiken
Copy link
Contributor Author

Would be awesome to have a PR with a falling test on this one 😄 @JustinAiken would you be able to do this?

Done in #955

@joaomdmoura
Copy link
Member

Yeah it's definitely related to #945, I'm interested in make this happen!
@JustinAiken made a great work writing the falling test, I'll try to pick up from there, but I'm kind busy with other couple features now, so in case some of you want to implement it just make yourself comfortable and let me know, otherwise I'll work on it once I finished this new PR, what might be this weekend 😄

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

Successfully merging a pull request may close this issue.

5 participants