Skip to content
This repository
Browse code

fix for Issue 4718

  • Loading branch information...
commit e2cea6cc5d912fffd1654209c168bf79705fa5bb 1 parent 4b96dd7
jenslukowski jenslukowski authored
9 activerecord/lib/active_record/relation/finder_methods.rb
@@ -318,7 +318,8 @@ def find_with_ids(*ids)
318 318 def find_one(id)
319 319 id = id.id if ActiveRecord::Base === id
320 320
321   - if IdentityMap.enabled? && where_values.blank? &&
  321 + if IdentityMap.enabled? &&
  322 + (where_values.blank? || contains_only_subclass_constraint?(where_values)) &&
322 323 limit_value.blank? && order_values.blank? &&
323 324 includes_values.blank? && preload_values.blank? &&
324 325 readonly_value.nil? && joins_values.blank? &&
@@ -394,5 +395,11 @@ def find_last
394 395 def using_limitable_reflections?(reflections)
395 396 reflections.none? { |r| r.collection? }
396 397 end
  398 +
  399 + def contains_only_subclass_constraint?(where_values)
  400 + where_values.length == 1 &&
  401 + !where_values[0].left.nil? && where_values[0].left.relation.name == table_name &&
  402 + !where_values[0].right.nil? && where_values[0].right.length == 1 && where_values[0].right[0] == @klass.name
  403 + end
397 404 end
398 405 end

0 comments on commit e2cea6c

Please sign in to comment.
Something went wrong with that request. Please try again.