cerebris / jsonapi-resources

A resource-focused Rails library for developing JSON:API compliant servers.
http://jsonapi-resources.com
MIT License
2.32k stars 532 forks source link

Serialized DB column throws `undefined method `associated_key'` error #669

Closed rickyhopkins closed 8 years ago

rickyhopkins commented 8 years ago

I have a text column in one of my models which I use to store serialized text in the form of a hash.

The code to perform this is:

class Message < ActiveRecord::Base
  serialize :template_data, Hash
end

This is working fine until it comes to my message_resource

class MessageResource < BaseResource
  ...
  attribute :template_data
  ...
end

Which is throwing the following error

Internal Server Error: undefined method `associated_key' for #<JSONAPI::CreateResourceOperation:0x007f5867e08370> /home/ricky/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/jsonapi-resources-0.7.0/lib/jsonapi/active_record_operations_processor.rb:29:in `rescue in block in process_operation'
/home/ricky/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/jsonapi-resources-0.7.0/lib/jsonapi/active_record_operations_processor.rb:22:in `block in process_operation'
/home/ricky/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/jsonapi-resources-0.7.0/lib/jsonapi/operations_processor.rb:90:in `with_default_handling'
/home/ricky/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/jsonapi-resources-0.7.0/lib/jsonapi/active_record_operations_processor.rb:21:in `process_operation'
/home/ricky/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/jsonapi-resources-0.7.0/lib/jsonapi/operations_processor.rb:53:in `block (5 levels) in process'
...

If I remove the template_data from my resource, or remove the serialize code from my model I do not get the error and everything runs fine.

rickyhopkins commented 8 years ago

Ok scratch this, it looks like there was an issue with my code which was causing the error