aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2005-05-02 05:34:27 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2005-05-02 05:34:27 +0000
commit5f77f64e924e0e40f5f141dd38df5d54335b7a46 (patch)
treed80737b3e0f7f98b58dc1cdad9b8c59232f81521 /activerecord/lib
parenta080b1a231ba26e3d74fd1770abc97068a9d7095 (diff)
downloadrails-5f77f64e924e0e40f5f141dd38df5d54335b7a46.tar.gz
rails-5f77f64e924e0e40f5f141dd38df5d54335b7a46.tar.bz2
rails-5f77f64e924e0e40f5f141dd38df5d54335b7a46.zip
Added option for passing an array to the find_all version of the dynamic finders and have it evaluated as an IN fragment
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1266 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/lib')
-rwxr-xr-xactiverecord/lib/active_record/base.rb10
1 files changed, 9 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb
index 283eb1070a..a74f8ce471 100755
--- a/activerecord/lib/active_record/base.rb
+++ b/activerecord/lib/active_record/base.rb
@@ -787,7 +787,7 @@ module ActiveRecord #:nodoc:
attributes.each { |attr_name| super unless column_methods_hash[attr_name.intern] }
attr_index = -1
- conditions = attributes.collect { |attr_name| attr_index += 1; "#{attr_name} #{arguments[attr_index].nil? ? "IS" : "="} ? " }.join(" AND ")
+ conditions = attributes.collect { |attr_name| attr_index += 1; "#{attr_name} #{attribute_condition(arguments[attr_index])} " }.join(" AND ")
if arguments[attributes.length].is_a?(Hash)
find(finder, { :conditions => [conditions, *arguments[0...attributes.length]]}.merge(arguments[attributes.length]))
@@ -800,6 +800,14 @@ module ActiveRecord #:nodoc:
end
end
+ def attribute_condition(argument)
+ case argument
+ when nil then "IS ?"
+ when Array then "IN (?)"
+ else "= ?"
+ end
+ end
+
# Defines an "attribute" method (like #inheritance_column or
# #table_name). A new (class) method will be created with the
# given name. If a value is specified, the new method will