Skip to content
Browse files

Abstract a bit more into SingularAssociation

  • Loading branch information...
1 parent 115eedb commit f1a15c2197d5da8e0c38bd59aa19973c9cfc0a01 @jonleighton jonleighton committed with tenderlove Jan 16, 2011
View
3 activerecord/lib/active_record/associations/belongs_to_association.rb
@@ -3,8 +3,7 @@ module ActiveRecord
module Associations
class BelongsToAssociation < SingularAssociation #:nodoc:
def replace(record)
- record = record.target if AssociationProxy === record
- raise_on_type_mismatch(record) if record
+ record = check_record(record)
update_counters(record)
replace_keys(record)
View
3 activerecord/lib/active_record/associations/has_one_association.rb
@@ -3,8 +3,7 @@ module ActiveRecord
module Associations
class HasOneAssociation < SingularAssociation #:nodoc:
def replace(record, save = true)
- record = record.target if AssociationProxy === record
- raise_on_type_mismatch(record) unless record.nil?
+ record = check_record(record)
load_target
@reflection.klass.transaction do
View
6 activerecord/lib/active_record/associations/singular_association.rb
@@ -26,6 +26,12 @@ def replace(record)
def set_new_record(record)
replace(record)
end
+
+ def check_record(record)
+ record = record.target if AssociationProxy === record
+ raise_on_type_mismatch(record) if record
+ record
+ end
end
end
end

0 comments on commit f1a15c2

Please sign in to comment.
Something went wrong with that request. Please try again.