Changeset 2748
- Timestamp:
- 10/26/05 13:20:02 (3 years ago)
- Files:
-
- trunk/activerecord/CHANGELOG (modified) (1 diff)
- trunk/activerecord/lib/active_record/base.rb (modified) (2 diffs)
- trunk/activerecord/test/base_test.rb (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/activerecord/CHANGELOG
r2741 r2748 1 1 *SVN* 2 3 * Added :offset and :limit to the kinds of options that Base.constrain can use #2466 [duane.johnson@gmail.com] 2 4 3 5 * Fixed handling of nil number columns on Oracle and cleaned up tests for Oracle in general #2555 [schoenm@earthlink.net] trunk/activerecord/lib/active_record/base.rb
r2730 r2748 810 810 811 811 # Add constraints to all queries to the same model in the given block. 812 # Currently supported constraints are <tt>:conditions</tt> and <tt>:joins</tt> 812 # Currently supported constraints are <tt>:conditions</tt>, <tt>:joins</tt>, 813 # <tt>:offset</tt>, and <tt>:limit</tt> 813 814 # 814 815 # Article.constrain(:conditions => "blog_id = 1") do … … 884 885 885 886 def add_limit!(sql, options) 887 options[:limit] ||= scope_constraints[:limit] if scope_constraints[:limit] 888 options[:offset] ||= scope_constraints[:offset] if scope_constraints[:offset] 886 889 connection.add_limit_offset!(sql, options) 887 890 end trunk/activerecord/test/base_test.rb
r2741 r2748 1040 1040 end 1041 1041 1042 def test_constrain_conditions 1043 developers = Developer.constrain(:conditions => 'salary > 90000') do 1044 Developer.find(:all, :conditions => 'id < 5') 1045 end 1046 david = Developer.find(1) 1047 assert !developers.include?(david) # David's salary is less than 90,000 1048 assert_equal 3, developers.size 1049 end 1050 1051 def test_constrain_limit_offset 1052 developers = Developer.constrain(:limit => 3, :offset => 2) do 1053 Developer.find(:all, :order => 'id') 1054 end 1055 david = Developer.find(1) 1056 jamis = Developer.find(1) 1057 assert !developers.include?(david) # David has id 1 1058 assert !developers.include?(jamis) # Jamis has id 2 1059 assert_equal 3, developers.size 1060 1061 # Now test without constraints to make sure we get the whole thing 1062 developers = Developer.find(:all, :order => 'id') 1063 assert_equal 10, developers.size 1064 end 1065 1042 1066 # FIXME: this test ought to run, but it needs to run sandboxed so that it 1043 1067 # doesn't b0rk the current test environment by undefing everything.