Module: ActiveRecord::NamedScope

Defined in:
lib/gems/activerecord-2.2.2/lib/active_record/named_scope.rb

Defined Under Namespace

Modules: ClassMethods Classes: Scope

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object

All subclasses of ActiveRecord::Base have two named scopes:

  • all - which is similar to a find(:all) query, and

  • scoped - which allows for the creation of anonymous scopes, on the fly: Shirt.scoped(:conditions => {:color => 'red'}).scoped(:include => :washing_instructions)

These anonymous scopes tend to be useful when procedurally generating complex queries, where passing intermediate values (scopes) around as first-class objects is convenient.



9
10
11
12
13
14
# File 'lib/gems/activerecord-2.2.2/lib/active_record/named_scope.rb', line 9

def self.included(base)
  base.class_eval do
    extend ClassMethods
    named_scope :scoped, lambda { |scope| scope }
  end
end