aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/associations/has_one_association.rb22
1 files changed, 8 insertions, 14 deletions
diff --git a/activerecord/lib/active_record/associations/has_one_association.rb b/activerecord/lib/active_record/associations/has_one_association.rb
index 285c2631ad..158ae376e1 100644
--- a/activerecord/lib/active_record/associations/has_one_association.rb
+++ b/activerecord/lib/active_record/associations/has_one_association.rb
@@ -2,22 +2,16 @@ module ActiveRecord
# = Active Record Belongs To Has One Association
module Associations
class HasOneAssociation < AssociationProxy #:nodoc:
- def create(attrs = {})
- new_record do |reflection|
- reflection.create_association(attrs)
- end
+ def create(attributes = {})
+ new_record(:create_association, attributes)
end
- def create!(attrs = {})
- new_record do |reflection|
- reflection.create_association!(attrs)
- end
+ def create!(attributes = {})
+ new_record(:create_association!, attributes)
end
- def build(attrs = {})
- new_record do |reflection|
- reflection.build_association(attrs)
- end
+ def build(attributes = {})
+ new_record(:build_association, attributes)
end
def replace(obj, dont_save = false)
@@ -69,8 +63,8 @@ module ActiveRecord
alias creation_attributes construct_owner_attributes
- def new_record
- record = scoped.scoping { yield @reflection }
+ def new_record(method, attributes)
+ record = scoped.scoping { @reflection.send(method, attributes) }
replace(record, true)
record
end