提交 bd19d09b 编写于 作者: Y Yves Senn 提交者: GitHub

Merge pull request #26381 from kamipo/extract_duplicated_create_for_association

Extract duplicated `create` and `create!` definition for association
...@@ -173,6 +173,14 @@ def initialize_attributes(record, except_from_scope_attributes = nil) #:nodoc: ...@@ -173,6 +173,14 @@ def initialize_attributes(record, except_from_scope_attributes = nil) #:nodoc:
set_inverse_instance(record) set_inverse_instance(record)
end end
def create(attributes = {}, &block)
_create_record(attributes, &block)
end
def create!(attributes = {}, &block)
_create_record(attributes, true, &block)
end
private private
def find_target? def find_target?
......
...@@ -113,14 +113,6 @@ def build(attributes = {}, &block) ...@@ -113,14 +113,6 @@ def build(attributes = {}, &block)
end end
end end
def create(attributes = {}, &block)
_create_record(attributes, &block)
end
def create!(attributes = {}, &block)
_create_record(attributes, true, &block)
end
# Add +records+ to this association. Returns +self+ so method calls may # Add +records+ to this association. Returns +self+ so method calls may
# be chained. Since << flattens its argument list and inserts each record, # be chained. Since << flattens its argument list and inserts each record,
# +push+ and +concat+ behave identically. # +push+ and +concat+ behave identically.
......
...@@ -23,14 +23,6 @@ def writer(record) ...@@ -23,14 +23,6 @@ def writer(record)
replace(record) replace(record)
end end
def create(attributes = {}, &block)
_create_record(attributes, &block)
end
def create!(attributes = {}, &block)
_create_record(attributes, true, &block)
end
def build(attributes = {}) def build(attributes = {})
record = build_record(attributes) record = build_record(attributes)
yield(record) if block_given? yield(record) if block_given?
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册