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
- Replace scopes with class methods In Rails 4 scopes do not work on abstract classes at the current moment. You can read more here: https://github.com/rails/rails/issues/10658 In order the gem to work... — committed to notonthehighstreet/action-mailer-queue by ventsislaf 10 years ago
- Fixes #10658 — committed to mmontossi/rails by mmontossi 9 years ago
- Fix scopes for abstract_class This bug still affects default_scope https://github.com/rails/rails/issues/10658 — committed to swrobel/meta-surf-forecast by swrobel 8 years ago
- Permit acts_as_paranoid to be given on abstract AR classes Works around https://github.com/rails/rails/issues/10658 and https://github.com/rails/rails/issues/23413. — committed to p-push/paranoia by p 8 years ago
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.