Browse files

fix for Issue 4718

  • Loading branch information...
1 parent 4b96dd7 commit e2cea6cc5d912fffd1654209c168bf79705fa5bb @jenslukowski jenslukowski committed Jan 29, 2012
Showing with 8 additions and 1 deletion.
  1. +8 −1 activerecord/lib/active_record/relation/finder_methods.rb
View
9 activerecord/lib/active_record/relation/finder_methods.rb
@@ -318,7 +318,8 @@ def find_with_ids(*ids)
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 @@ def find_last
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

0 comments on commit e2cea6c

Please sign in to comment.