diff options
author | Jon Leighton <j@jonathanleighton.com> | 2011-01-06 19:42:31 +0000 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2011-01-07 15:03:15 -0800 |
commit | d23c332e02932a6a06853193c79a21d70dbe139e (patch) | |
tree | 750c1f485a1fdccca06ac7d684a7f0ace57412ea /activerecord/lib | |
parent | 5ecf6922487b5476509af2a89137c3cd3791f7ab (diff) | |
download | rails-d23c332e02932a6a06853193c79a21d70dbe139e.tar.gz rails-d23c332e02932a6a06853193c79a21d70dbe139e.tar.bz2 rails-d23c332e02932a6a06853193c79a21d70dbe139e.zip |
Clean up create, create! and build in HasOneAssociation
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/associations/has_one_association.rb | 22 |
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 |