From 109926c5a3472dd08b921b7729c0457ad23dcbf8 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Fri, 25 May 2007 21:56:21 +0000 Subject: Find with a list of ids supports limit/offset. Closes #8437. git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6845 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- activerecord/lib/active_record/base.rb | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'activerecord/lib/active_record/base.rb') diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index 608651cd0a..81b492e65e 100755 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -1117,10 +1117,21 @@ module ActiveRecord #:nodoc: result = find_every(options) - if result.size == ids.size + # If the user passes in a limit to find(), we need to check + # to see if the result is limited before just checking the + # size of the results. + expected_size = + if options[:limit] && ids.size > options[:limit] + options[:limit] + else + ids.size + end + expected_size -= options[:offset] if options[:offset] + + if result.size == expected_size result else - raise RecordNotFound, "Couldn't find all #{name.pluralize} with IDs (#{ids_list})#{conditions}" + raise RecordNotFound, "Couldn't find all #{name.pluralize} with IDs (#{ids_list})#{conditions} (found #{result.size} results, but was looking for #{expected_size})" end end -- cgit v1.2.3