提交 d23c332e 编写于 作者: J Jon Leighton 提交者: Aaron Patterson

Clean up create, create! and build in HasOneAssociation

上级 5ecf6922
......@@ -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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册