rails: Scopes defined on Abstract ActiveRecord classes are missing table names when called from subclasses

If a scope is defined on an abstract active record class, when it is called by one of its subclasses the sql generated is missing a table name.

class AbstractCompany < ActiveRecord::Base
  self.abstract_class = true

  scope :abstract_company_scope, ->{ order('id') }
end

class Company < AbstractCompany
end

Company.abstract_company_scope #=> ActiveRecord::StatementInvalid: SQLite3::SQLException: no such table: : SELECT  "".* FROM ""   ORDER BY id LIMIT 1

Test has been added at lsylvester/rails@c64023bc9fd7dfe10f564fedbd7299240bd5da15

About this issue

  • Original URL
  • State: closed
  • Created 11 years ago
  • Comments: 42 (26 by maintainers)

Commits related to this issue

Most upvoted comments

Not fixed in Rails 4.2.7.1

+1 We’re running into this issue on our project as well. Would love to see this patch merged in.