From d23c332e02932a6a06853193c79a21d70dbe139e Mon Sep 17 00:00:00 2001 From: Jon Leighton Date: Thu, 6 Jan 2011 19:42:31 +0000 Subject: Clean up create, create! and build in HasOneAssociation --- .../associations/has_one_association.rb | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) (limited to 'activerecord/lib/active_record') 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 -- cgit v1.2.3