diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2016-09-03 20:21:01 +0900 |
---|---|---|
committer | Ryuta Kamizono <kamipo@gmail.com> | 2016-09-03 20:21:01 +0900 |
commit | dd5cba852fe3a2503bce66530d1aa14ed2032e2c (patch) | |
tree | a75b3e45235f56de1248faadf3b8ea2b6705a8a6 /activerecord | |
parent | 57b95c39869e20ef4db9850b9328e6ea52ca7377 (diff) | |
download | rails-dd5cba852fe3a2503bce66530d1aa14ed2032e2c.tar.gz rails-dd5cba852fe3a2503bce66530d1aa14ed2032e2c.tar.bz2 rails-dd5cba852fe3a2503bce66530d1aa14ed2032e2c.zip |
Extract duplicated `create` and `create!` definition for association
Diffstat (limited to 'activerecord')
3 files changed, 8 insertions, 16 deletions
diff --git a/activerecord/lib/active_record/associations/association.rb b/activerecord/lib/active_record/associations/association.rb index 8328286805..f506614591 100644 --- a/activerecord/lib/active_record/associations/association.rb +++ b/activerecord/lib/active_record/associations/association.rb @@ -173,6 +173,14 @@ module ActiveRecord set_inverse_instance(record) end + def create(attributes = {}, &block) + _create_record(attributes, &block) + end + + def create!(attributes = {}, &block) + _create_record(attributes, true, &block) + end + private def find_target? diff --git a/activerecord/lib/active_record/associations/collection_association.rb b/activerecord/lib/active_record/associations/collection_association.rb index 0c911a5396..5ee6960c86 100644 --- a/activerecord/lib/active_record/associations/collection_association.rb +++ b/activerecord/lib/active_record/associations/collection_association.rb @@ -113,14 +113,6 @@ module ActiveRecord 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 # be chained. Since << flattens its argument list and inserts each record, # +push+ and +concat+ behave identically. diff --git a/activerecord/lib/active_record/associations/singular_association.rb b/activerecord/lib/active_record/associations/singular_association.rb index 1fe9a23263..483a9df740 100644 --- a/activerecord/lib/active_record/associations/singular_association.rb +++ b/activerecord/lib/active_record/associations/singular_association.rb @@ -23,14 +23,6 @@ module ActiveRecord replace(record) end - def create(attributes = {}, &block) - _create_record(attributes, &block) - end - - def create!(attributes = {}, &block) - _create_record(attributes, true, &block) - end - def build(attributes = {}) record = build_record(attributes) yield(record) if block_given? |