diff options
author | Egor Lynko <flexoid@gmail.com> | 2012-05-30 00:36:28 +0300 |
---|---|---|
committer | Egor Lynko <flexoid@gmail.com> | 2012-06-25 18:30:15 +0300 |
commit | 359592bba6cb85b43ca8945917b1ca57fa7494a9 (patch) | |
tree | 215a7c8cd7c1074b0d8b6e64ece9785e89b854bd /activerecord/lib | |
parent | 24a4cc741a948cd4a01d172a3bfbd68c509b4448 (diff) | |
download | rails-359592bba6cb85b43ca8945917b1ca57fa7494a9.tar.gz rails-359592bba6cb85b43ca8945917b1ca57fa7494a9.tar.bz2 rails-359592bba6cb85b43ca8945917b1ca57fa7494a9.zip |
exists?(false) returns false
`FinderMethods#exists?` finder method now returns *false* with the *false* argument
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/relation/finder_methods.rb | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/activerecord/lib/active_record/relation/finder_methods.rb b/activerecord/lib/active_record/relation/finder_methods.rb index c91758265b..e6a67b76fe 100644 --- a/activerecord/lib/active_record/relation/finder_methods.rb +++ b/activerecord/lib/active_record/relation/finder_methods.rb @@ -170,19 +170,19 @@ module ActiveRecord # Person.exists?(['name LIKE ?', "%#{query}%"]) # Person.exists?(:name => "David") # Person.exists? - def exists?(id = false) - id = id.id if ActiveRecord::Model === id - return false if id.nil? + def exists?(conditions = :none) + conditions = conditions.id if ActiveRecord::Model === conditions + return false if !conditions join_dependency = construct_join_dependency_for_association_find relation = construct_relation_for_association_find(join_dependency) relation = relation.except(:select, :order).select("1 AS one").limit(1) - case id + case conditions when Array, Hash - relation = relation.where(id) + relation = relation.where(conditions) else - relation = relation.where(table[primary_key].eq(id)) if id + relation = relation.where(table[primary_key].eq(conditions)) if conditions != :none end connection.select_value(relation, "#{name} Exists", relation.bind_values) |