From c943683141f79f5c80f642dbd51ef06ab051ee9b Mon Sep 17 00:00:00 2001 From: Shishir Kakaraddi Date: Thu, 26 Apr 2018 22:01:32 -0700 Subject: [PATCH] second attempt to fix the has one name collision issue --- lib/extensions/has_one.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/extensions/has_one.rb b/lib/extensions/has_one.rb index 9016222..930ca57 100644 --- a/lib/extensions/has_one.rb +++ b/lib/extensions/has_one.rb @@ -9,10 +9,10 @@ if defined?(::ActiveRecord) super name = reflection.name mixin.class_eval <<-CODE, __FILE__, __LINE__ + 1 - unless defined? #{name}_id - def #{name}_id - association(:#{name}).reader.try(:id) - end + def #{name}_id + # if an attribute is already defined with this methods name we should just use it + return read_attribute(__method__) if has_attribute?(__method__) + association(:#{name}).reader.try(:id) end CODE end