aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorGeorg Friedrich <georg@wobolando.com>2011-09-05 21:25:57 +1000
committerAaron Patterson <aaron.patterson@gmail.com>2011-09-05 13:49:29 -0700
commit21750122308a38cd2eaf9b46aa1789966eb8abd9 (patch)
treed0035fcbae56208fc6bb62763c34584434d588b7 /activerecord/lib
parent7f7e362c14b4d462e3b796219d3b68c076b01643 (diff)
downloadrails-21750122308a38cd2eaf9b46aa1789966eb8abd9.tar.gz
rails-21750122308a38cd2eaf9b46aa1789966eb8abd9.tar.bz2
rails-21750122308a38cd2eaf9b46aa1789966eb8abd9.zip
Don't find belongs_to target when the foreign_key is NULL. Fixes #2828
Diffstat (limited to 'activerecord/lib')
-rw-r--r--activerecord/lib/active_record/associations/belongs_to_association.rb4
1 files changed, 4 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/associations/belongs_to_association.rb b/activerecord/lib/active_record/associations/belongs_to_association.rb
index adb6af7165..58c9648ce8 100644
--- a/activerecord/lib/active_record/associations/belongs_to_association.rb
+++ b/activerecord/lib/active_record/associations/belongs_to_association.rb
@@ -20,6 +20,10 @@ module ActiveRecord
private
+ def find_target?
+ !loaded? && foreign_key_present? && klass
+ end
+
def update_counters(record)
counter_cache_name = reflection.counter_cache_column