Skip to content

Commit

Permalink
Abstract a bit more into SingularAssociation
Browse files Browse the repository at this point in the history
  • Loading branch information
jonleighton authored and tenderlove committed Jan 16, 2011
1 parent 115eedb commit f1a15c2
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.