Skip to content

Rails STI subclasses being "forgotten" when env auto-reloads #340

@fbatista

Description

@fbatista

Consider the following structure:

class Section < ActiveRecord::Base
  belongs_to :sectionable, polymorphic: true
end

class MarketSection < Section
end

class MarketNotesSection < MarketSection
end

When doing a query for sectionables that have has_many :market_sections, as: :sectionable , on the first run after the environment is loaded, it correctly performs sections.type IN ('MarketSection', 'MarketNotesSection'), because i added an initializer to preload the classes in development, as suggested in http://www.alexreisner.com/code/single-table-inheritance-in-rails for example.

However, as soon as i edit and save a bit of code (a controller for example), the environment "forgets" about the subclass of marketsection and stops including it in the query.

I'd be happy to provide more details if needed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions