Skip to content

Commit

Permalink
[#492 state:resolved] correctly propagate automatic scopes to subclasses
Browse files Browse the repository at this point in the history
  • Loading branch information
al2o3cr committed Nov 30, 2009
1 parent b94526c commit 04cfc5b
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion hobo/lib/hobo/scopes/automatic_scopes.rb
Expand Up @@ -347,7 +347,15 @@ def reflection(name)


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


Expand Down

0 comments on commit 04cfc5b

Please sign in to comment.