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

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

@shosanna

Description

@shosanna

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions