diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2008-11-16 16:01:18 +0100 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2008-11-16 16:01:18 +0100 |
commit | ff594b2bc94ff2a942fe6ca05672387722dee686 (patch) | |
tree | bac4e060858eb2fdab50401a6cef1b2196bed452 /activerecord/lib | |
parent | c5448c75abd7b69618346fe62deb7a7a3442f4e8 (diff) | |
download | rails-ff594b2bc94ff2a942fe6ca05672387722dee686.tar.gz rails-ff594b2bc94ff2a942fe6ca05672387722dee686.tar.bz2 rails-ff594b2bc94ff2a942fe6ca05672387722dee686.zip |
Added default_scope to Base [#1381 state:committed] (Paweł Kondzior)
Diffstat (limited to 'activerecord/lib')
-rwxr-xr-x | activerecord/lib/active_record/base.rb | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index dcc8277849..9481c12b26 100755 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -2016,6 +2016,16 @@ module ActiveRecord #:nodoc: @@subclasses[self] + extra = @@subclasses[self].inject([]) {|list, subclass| list + subclass.subclasses } end + # Sets the default options for the model. The format of the + # <tt>method_scoping</tt> argument is the same as in with_scope. + # + # class Person << ActiveRecord::Base + # default_scope :find => { :order => 'last_name, first_name' } + # end + def default_scope(options = {}) + self.scoped_methods << { :find => options, :create => options.is_a?(Hash) ? options[:conditions] : {} } + end + # Test whether the given method and optional key are scoped. def scoped?(method, key = nil) #:nodoc: if current_scoped_methods && (scope = current_scoped_methods[method]) |