Skip to content
This repository was archived by the owner on Oct 19, 2018. It is now read-only.
This repository was archived by the owner on Oct 19, 2018. It is now read-only.

active_record finders ignores STI class #39

@sfcgeorge

Description

@sfcgeorge

If single table inheritance is used on the back end, hyper-mesh won't instantiate the correct subclass, only ever the parent class.

# field.string :type
class User < ActiveRecord
  def self.meaningful
    find(42)
  end
end

class Employer < User
end

Employer.create.id # 42
Employer.meaningful.class #=> User (should be Employer)
User.meaningful.class #=> User (should also be Employer!)

The AR method becomes should also be added to allow switching class:

User.find.becomes(User)
Employer.find.becomes(User)

Basically Rails always automatically converts into the most specific STI sub-class.

Fairly sure this will fix #38 too

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions