public
Fork of rails/rails
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/JackDanger/rails.git
Enable Limit/Offset in Calculations (closes #4558) [lmarlow@yahoo.com]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4185 
5ecf4fe2-1ee6-0310-87b1-e25e094e27de
technoweenie (author)
Thu Apr 06 08:23:56 -0700 2006
commit  52d298a8bd5800d9149b0b288bd8a929110b5260
tree    7f6cb3528dd30c9593875c38da820125d4ba8427
parent  944ae628f529a5392a543a88186415e87f462009
...
1
2
 
 
3
4
5
...
1
2
3
4
5
6
7
0
@@ -1,5 +1,7 @@
0
 *1.14.1* (April 6th, 2005)
0
 
0
+* Enable Limit/Offset in Calculations (closes #4558) [lmarlow@yahoo.com]
0
+
0
 * Fixed that loading including associations returns all results if Load IDs For Limited Eager Loading returns none (closes #4528) [Rick]
0
 
0
 * Fixed HasManyAssociation#find bugs when :finder_sql is set #4600 [lagroue@free.fr]
...
1
2
3
 
4
5
6
...
153
154
155
 
156
157
158
...
1
2
 
3
4
5
6
...
153
154
155
156
157
158
159
0
@@ -1,6 +1,6 @@
0
 module ActiveRecord
0
   module Calculations #:nodoc:
0
- CALCULATIONS_OPTIONS = [:conditions, :joins, :order, :select, :group, :having, :distinct]
0
+ CALCULATIONS_OPTIONS = [:conditions, :joins, :order, :select, :group, :having, :distinct, :limit, :offset]
0
     def self.included(base)
0
       base.extend(ClassMethods)
0
     end
0
@@ -153,6 +153,7 @@ module ActiveRecord
0
           sql << " GROUP BY #{options[:group_field]}" if options[:group]
0
           sql << " HAVING #{options[:having]}" if options[:group] && options[:having]
0
           sql << " ORDER BY #{options[:order]}" if options[:order]
0
+ add_limit!(sql, options)
0
           sql.join
0
         end
0
 
...
48
49
50
 
 
 
 
 
 
 
 
 
 
 
 
51
52
53
...
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
0
@@ -48,6 +48,18 @@ class CalculationsTest < Test::Unit::TestCase
0
     assert_equal [6, 2, 1], c.keys.compact
0
   end
0
 
0
+ def test_should_limit_calculation
0
+ c = Account.sum(:credit_limit, :conditions => "firm_id IS NOT NULL",
0
+ :group => :firm_id, :order => "firm_id", :limit => 2)
0
+ assert_equal [1, 2], c.keys.compact
0
+ end
0
+
0
+ def test_should_limit_calculation_with_offset
0
+ c = Account.sum(:credit_limit, :conditions => "firm_id IS NOT NULL",
0
+ :group => :firm_id, :order => "firm_id", :limit => 2, :offset => 1)
0
+ assert_equal [2, 6], c.keys.compact
0
+ end
0
+
0
   def test_should_group_by_summed_field_having_condition
0
     c = Account.sum(:credit_limit, :group => :firm_id,
0
                                    :having => 'sum(credit_limit) > 50')

Comments

    No one has commented yet.