Skip to content
This repository has been archived by the owner on Jun 5, 2020. It is now read-only.

Single table inheritance - type field breaks load_instance when cached #36

Open
shosanna opened this issue Aug 27, 2014 · 0 comments
Open

Comments

@shosanna
Copy link

I noticed that if I am using a type column in my object and I want to cache it, I run into unexpected problems. I believe the reason lies in activity.rb

  # stores the correct class
  hash = {'id' => object.id, 'type' => object.class.name}

  if fields = definition.send(type)[class_sym].try(:[],:cache)
    fields.each do |field|
      raise Errors::InvalidField.new(field) unless object.respond_to?(field)
      # here it gets overriten by STI "type" field
      hash[field.to_s] = object.send(field)
    end
  end
  write_attribute(type, hash)
end

Where the type is rewritten by the one from the model's attributes and the load_instance is than throwing an error because it could not find an object based on this type. Note that this only happens if the type column is being cached.

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

No branches or pull requests

1 participant