From 2fdbdddbc0850d11f59d5fbfa6edc611924befd6 Mon Sep 17 00:00:00 2001 From: Carlos Antonio da Silva Date: Fri, 21 Feb 2014 12:35:56 -0300 Subject: [PATCH] Merge pull request #14140 from WojtekKruszewski/optimize_foreign_key_for Prevent foreign_key_for? from evaluating all attributes --- activerecord/lib/active_record/associations/association.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/activerecord/lib/active_record/associations/association.rb b/activerecord/lib/active_record/associations/association.rb index 4e462568626bf..9ad2d2fb12ccd 100644 --- a/activerecord/lib/active_record/associations/association.rb +++ b/activerecord/lib/active_record/associations/association.rb @@ -232,7 +232,7 @@ def invertible_for?(record) # Returns true if record contains the foreign_key def foreign_key_for?(record) - record.attributes.has_key? reflection.foreign_key + record.has_attribute?(reflection.foreign_key) end # This should be implemented to return the values of the relevant key(s) on the owner,