aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/associations/has_one_association.rb
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord/lib/active_record/associations/has_one_association.rb')
-rw-r--r--activerecord/lib/active_record/associations/has_one_association.rb26
1 files changed, 13 insertions, 13 deletions
diff --git a/activerecord/lib/active_record/associations/has_one_association.rb b/activerecord/lib/active_record/associations/has_one_association.rb
index a0828dcdea..9b51abc93b 100644
--- a/activerecord/lib/active_record/associations/has_one_association.rb
+++ b/activerecord/lib/active_record/associations/has_one_association.rb
@@ -6,19 +6,19 @@ module ActiveRecord
record = check_record(record)
load_target
- @reflection.klass.transaction do
- if @target && @target != record
- remove_target!(@reflection.options[:dependent])
+ reflection.klass.transaction do
+ if target && target != record
+ remove_target!(reflection.options[:dependent])
end
if record
set_inverse_instance(record)
set_owner_attributes(record)
- if @owner.persisted? && save && !record.save
+ if owner.persisted? && save && !record.save
nullify_owner_attributes(record)
- set_owner_attributes(@target)
- raise RecordNotSaved, "Failed to save the new associated #{@reflection.name}."
+ set_owner_attributes(target)
+ raise RecordNotSaved, "Failed to save the new associated #{reflection.name}."
end
end
end
@@ -29,7 +29,7 @@ module ActiveRecord
protected
def association_scope
- super.order(@reflection.options[:order])
+ super.order(reflection.options[:order])
end
private
@@ -46,20 +46,20 @@ module ActiveRecord
def remove_target!(method)
if [:delete, :destroy].include?(method)
- @target.send(method)
+ target.send(method)
else
- nullify_owner_attributes(@target)
+ nullify_owner_attributes(target)
- if @target.persisted? && @owner.persisted? && !@target.save
- set_owner_attributes(@target)
- raise RecordNotSaved, "Failed to remove the existing associated #{@reflection.name}. " +
+ if target.persisted? && owner.persisted? && !target.save
+ set_owner_attributes(target)
+ raise RecordNotSaved, "Failed to remove the existing associated #{reflection.name}. " +
"The record failed to save when after its foreign key was set to nil."
end
end
end
def nullify_owner_attributes(record)
- record[@reflection.foreign_key] = nil
+ record[reflection.foreign_key] = nil
end
end
end