aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/relation
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2012-01-31 10:53:16 -0800
committerAaron Patterson <aaron.patterson@gmail.com>2012-01-31 10:53:16 -0800
commit5cad7a0dba652f3e942e58087bc88ba5c5390edc (patch)
tree6768d8695fcb075187fcf1364b164aec6d90ecc1 /activerecord/lib/active_record/relation
parentbb842e8d2111e50b21a14b8bd6d89371a4b9cd68 (diff)
parente2cea6cc5d912fffd1654209c168bf79705fa5bb (diff)
downloadrails-5cad7a0dba652f3e942e58087bc88ba5c5390edc.tar.gz
rails-5cad7a0dba652f3e942e58087bc88ba5c5390edc.tar.bz2
rails-5cad7a0dba652f3e942e58087bc88ba5c5390edc.zip
Merge pull request #4746 from jenslukowski/issue4718
Test and fix for issue 4718
Diffstat (limited to 'activerecord/lib/active_record/relation')
-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