aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorJens Lukowski <jens.lukowski@digitalpaperplanes.com>2012-01-29 21:53:35 +0100
committerJens Lukowski <jens.lukowski@digitalpaperplanes.com>2012-01-29 21:53:35 +0100
commite2cea6cc5d912fffd1654209c168bf79705fa5bb (patch)
tree14207421dfb6e244e1e7d9457294ad9ccdf014f9 /activerecord/lib
parent4b96dd7962a052af17b9c3a1fe39f4269c4f96c9 (diff)
downloadrails-e2cea6cc5d912fffd1654209c168bf79705fa5bb.tar.gz
rails-e2cea6cc5d912fffd1654209c168bf79705fa5bb.tar.bz2
rails-e2cea6cc5d912fffd1654209c168bf79705fa5bb.zip
fix for Issue 4718
Diffstat (limited to 'activerecord/lib')
-rw-r--r--activerecord/lib/active_record/relation/finder_methods.rb9
1 files changed, 8 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/relation/finder_methods.rb b/activerecord/lib/active_record/relation/finder_methods.rb
index f1ac421a50..b54a167dc3 100644
--- a/activerecord/lib/active_record/relation/finder_methods.rb
+++ b/activerecord/lib/active_record/relation/finder_methods.rb
@@ -318,7 +318,8 @@ module ActiveRecord
def find_one(id)
id = id.id if ActiveRecord::Base === id
- if IdentityMap.enabled? && where_values.blank? &&
+ if IdentityMap.enabled? &&
+ (where_values.blank? || contains_only_subclass_constraint?(where_values)) &&
limit_value.blank? && order_values.blank? &&
includes_values.blank? && preload_values.blank? &&
readonly_value.nil? && joins_values.blank? &&
@@ -394,5 +395,11 @@ module ActiveRecord
def using_limitable_reflections?(reflections)
reflections.none? { |r| r.collection? }
end
+
+ def contains_only_subclass_constraint?(where_values)
+ where_values.length == 1 &&
+ !where_values[0].left.nil? && where_values[0].left.relation.name == table_name &&
+ !where_values[0].right.nil? && where_values[0].right.length == 1 && where_values[0].right[0] == @klass.name
+ end
end
end