lib/hobo/scopes/automatic_scopes.rb in hobo-0.9.0 vs lib/hobo/scopes/automatic_scopes.rb in hobo-0.9.100
- old
+ new
@@ -345,10 +345,18 @@
@klass.reflections[name.to_sym]
end
def def_scope(options={}, &block)
- @klass.named_scope(name.to_sym, block || options)
+ _name = name.to_sym
+ @klass.named_scope(_name, block || options)
+ # this is tricky; ordinarily, we'd worry about subclasses that haven't yet been loaded.
+ # HOWEVER, they will pick up the scope setting via read_inheritable_attribute when they do
+ # load, so only the currently existing subclasses need to be fixed up.
+ _scope = @klass.scopes[_name]
+ @klass.send(:subclasses).each do |k|
+ k.scopes[_name] = _scope
+ end
end
def primary_key_column(refl)
"#{refl.klass.table_name}.#{refl.klass.primary_key}"