Permalink
Browse files

remove nil check

calling replace_keys could possibly do a nil check twice, this commit
reduces it to once.
  • Loading branch information...
1 parent c76549d commit 1678e959e973de32287b65c52ebc6cce87148951 @tenderlove tenderlove committed Dec 12, 2013
@@ -11,7 +11,11 @@ def replace(record)
raise_on_type_mismatch!(record) if record
update_counters(record)
- replace_keys(record)
+ if record
+ replace_keys(record)
+ else
+ remove_keys
+ end
set_inverse_instance(record) if record
@updated = true if record
@@ -58,11 +62,11 @@ def different_target?(record)
end
def replace_keys(record)
- if record
- owner[reflection.foreign_key] = record[reflection.association_primary_key(record.class)]
- else
- owner[reflection.foreign_key] = nil
- end
+ owner[reflection.foreign_key] = record[reflection.association_primary_key(record.class)]
+ end
+
+ def remove_keys
+ owner[reflection.foreign_key] = nil
end
def foreign_key_present?
@@ -11,7 +11,7 @@ def klass
def replace_keys(record)
super
- owner[reflection.foreign_type] = record && record.class.base_class.name
+ owner[reflection.foreign_type] = record.class.base_class.name
end
def different_target?(record)

0 comments on commit 1678e95

Please sign in to comment.