Permalink
Browse files

Clean up create, create! and build in HasOneAssociation

  • Loading branch information...
jonleighton authored and tenderlove committed Jan 6, 2011
1 parent 5ecf692 commit d23c332e02932a6a06853193c79a21d70dbe139e
Showing with 8 additions and 14 deletions.
  1. +8 −14 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 @@ def association_scope
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

0 comments on commit d23c332

Please sign in to comment.