From 21750122308a38cd2eaf9b46aa1789966eb8abd9 Mon Sep 17 00:00:00 2001 From: Georg Friedrich Date: Mon, 5 Sep 2011 21:25:57 +1000 Subject: Don't find belongs_to target when the foreign_key is NULL. Fixes #2828 --- activerecord/lib/active_record/associations/belongs_to_association.rb | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'activerecord/lib') 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 -- cgit v1.2.3