<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -1,3 +1,19 @@
+*2.3.0/3.0*
+
+* Added default_scope to Base #1381 [Pawe&#322; Kondzior]. Example:
+
+    class Person &lt; ActiveRecord::Base
+      default_scope :order =&gt; 'last_name, first_name'
+    end
+
+    class Company &lt; ActiveRecord::Base
+      has_many :people
+    end
+
+    Person.all             # =&gt; Person.find(:all, :order =&gt; 'last_name, first_name')
+    Company.find(1).people # =&gt; Person.find(:all, :order =&gt; 'last_name, first_name', :conditions =&gt; { :company_id =&gt; 1 })
+
+
 *2.2.1 [RC2] (November 14th, 2008)*
 
 * Ensure indices don't flip order in schema.rb #1266 [Jordi Bunster]</diff>
      <filename>activerecord/CHANGELOG</filename>
    </modified>
    <modified>
      <diff>@@ -495,6 +495,10 @@ module ActiveRecord #:nodoc:
     superclass_delegating_accessor :store_full_sti_class
     self.store_full_sti_class = false
 
+    # Stores the default scope for the class
+    class_inheritable_accessor :default_scoping, :instance_writer =&gt; false
+    self.default_scoping = []
+
     class &lt;&lt; self # Class methods
       # Find operates with four different retrieval approaches:
       #
@@ -2016,6 +2020,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
+        # &lt;tt&gt;method_scoping&lt;/tt&gt; argument is the same as in with_scope.
+        #
+        #   class Person &lt; ActiveRecord::Base
+        #     default_scope :find =&gt; { :order =&gt; 'last_name, first_name' }
+        #   end
+        def default_scope(options = {})
+          self.default_scoping &lt;&lt; { :find =&gt; options, :create =&gt; 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 &amp;&amp; (scope = current_scoped_methods[method])
@@ -2031,7 +2045,7 @@ module ActiveRecord #:nodoc:
         end
 
         def scoped_methods #:nodoc:
-          Thread.current[:&quot;#{self}_scoped_methods&quot;] ||= []
+          Thread.current[:&quot;#{self}_scoped_methods&quot;] ||= self.default_scoping
         end
 
         def current_scoped_methods #:nodoc:</diff>
      <filename>activerecord/lib/active_record/base.rb</filename>
    </modified>
    <modified>
      <diff>@@ -522,6 +522,67 @@ class HasAndBelongsToManyScopingTest&lt; ActiveRecord::TestCase
 end
 
 
+class DefaultScopingTest &lt; ActiveRecord::TestCase
+  fixtures :developers
+
+  def test_default_scope
+    expected = Developer.find(:all, :order =&gt; 'salary DESC').collect { |dev| dev.salary }
+    received = DeveloperOrderedBySalary.find(:all).collect { |dev| dev.salary }
+    assert_equal expected, received
+  end
+
+  def test_default_scoping_with_threads
+    scope = [{:create=&gt;nil, :find=&gt;{:order=&gt;&quot;salary DESC&quot;}}]
+
+    2.times do
+      Thread.new { assert_equal scope, DeveloperOrderedBySalary.send(:scoped_methods) }.join
+    end
+  end
+
+  def test_default_scoping_with_inheritance
+    scope = [{:create=&gt;nil, :find=&gt;{:order=&gt;&quot;salary DESC&quot;}}]
+
+    # Inherit a class having a default scope and define a new default scope
+    klass = Class.new(DeveloperOrderedBySalary)
+    klass.send :default_scope, {}
+
+    # Scopes added on children should append to parent scope
+    expected_klass_scope = [{:create=&gt;nil, :find=&gt;{:order=&gt;&quot;salary DESC&quot;}}, {:create=&gt;nil, :find=&gt;{}}]
+    assert_equal expected_klass_scope, klass.send(:scoped_methods)
+    
+    # Parent should still have the original scope
+    assert_equal scope, DeveloperOrderedBySalary.send(:scoped_methods)
+  end
+
+  def test_method_scope
+    expected = Developer.find(:all, :order =&gt; 'name DESC').collect { |dev| dev.salary }
+    received = DeveloperOrderedBySalary.all_ordered_by_name.collect { |dev| dev.salary }
+    assert_equal expected, received
+  end
+
+  def test_nested_scope
+    expected = Developer.find(:all, :order =&gt; 'name DESC').collect { |dev| dev.salary }
+    received = DeveloperOrderedBySalary.with_scope(:find =&gt; { :order =&gt; 'name DESC'}) do
+      DeveloperOrderedBySalary.find(:all).collect { |dev| dev.salary }
+    end
+    assert_equal expected, received
+  end
+
+  def test_nested_exclusive_scope
+    expected = Developer.find(:all, :limit =&gt; 100).collect { |dev| dev.salary }
+    received = DeveloperOrderedBySalary.with_exclusive_scope(:find =&gt; { :limit =&gt; 100 }) do
+      DeveloperOrderedBySalary.find(:all).collect { |dev| dev.salary }
+    end
+    assert_equal expected, received
+  end
+
+  def test_overwriting_default_scope
+    expected = Developer.find(:all, :order =&gt; 'salary').collect { |dev| dev.salary }
+    received = DeveloperOrderedBySalary.find(:all, :order =&gt; 'salary').collect { |dev| dev.salary }
+    assert_equal expected, received
+  end
+end
+
 =begin
 # We disabled the scoping for has_one and belongs_to as we can't think of a proper use case
 </diff>
      <filename>activerecord/test/cases/method_scoping_test.rb</filename>
    </modified>
    <modified>
      <diff>@@ -77,3 +77,15 @@ class DeveloperWithBeforeDestroyRaise &lt; ActiveRecord::Base
     raise if projects.empty?
   end
 end
+
+class DeveloperOrderedBySalary &lt; ActiveRecord::Base
+    self.table_name = 'developers'
+    default_scope :order =&gt; &quot;salary DESC&quot;
+
+    def self.all_ordered_by_name
+      with_scope(:find =&gt; { :order =&gt; &quot;name DESC&quot; }) do
+        find(:all)
+      end
+    end
+
+end</diff>
      <filename>activerecord/test/models/developer.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>d9f460a39b73fd2cf0f17f523cc4810d0bf44cac</id>
    </parent>
  </parents>
  <author>
    <name>Pratik Naik</name>
    <login>lifo</login>
    <email>pratiknaik@gmail.com</email>
  </author>
  <url>http://github.com/rails/rails/commit/2530d0eea8eaecd2c61f99225f050ff47973e9a0</url>
  <id>2530d0eea8eaecd2c61f99225f050ff47973e9a0</id>
  <committed-date>2008-11-16T10:06:41-08:00</committed-date>
  <authored-date>2008-11-16T10:06:41-08:00</authored-date>
  <message>Added default_scope to Base [#1381 state:committed] (Pawe&#322; Kondzior)</message>
  <tree>e32d4920a21417e79584c6c7a563a2cb948b4532</tree>
  <committer>
    <name>Pratik Naik</name>
    <login>lifo</login>
    <email>pratiknaik@gmail.com</email>
  </committer>
</commit>
