ruby-on-railsrubyactiverecordsingle-table-inheritanceruby-2.0

Single Table Inheritance (STI) parent ActiveRecord .subclasses .descendants returns empty


I have a STI in place for 10 models inheriting from one ActiveRecord::Base model.

class Listing::Numeric < ActiveRecord::Base
end

class Listing::AverageDuration < Listing::Numeric
end

class Listing::TotalViews < Listing::Numeric
end

There are 10 such models those inherit from Listing::Numeric

In rails console, when I try for .descendants or .subclasses it returns an empty array.

Listing::Numeric.descendants
=> []

Listing::Numeric.subclasses
=> []

Ideally this should work.

Any ideas why its not returning the expected subclasses ?


Solution

  • This helped me

    config.autoload_paths += %W( #{config.root}/app/models/listings )

    Taken from here - http://hakunin.com/rails3-load-paths