aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record
diff options
context:
space:
mode:
authorRyuta Kamizono <kamipo@gmail.com>2016-09-03 20:21:01 +0900
committerRyuta Kamizono <kamipo@gmail.com>2016-09-03 20:21:01 +0900
commitdd5cba852fe3a2503bce66530d1aa14ed2032e2c (patch)
treea75b3e45235f56de1248faadf3b8ea2b6705a8a6 /activerecord/lib/active_record
parent57b95c39869e20ef4db9850b9328e6ea52ca7377 (diff)
downloadrails-dd5cba852fe3a2503bce66530d1aa14ed2032e2c.tar.gz
rails-dd5cba852fe3a2503bce66530d1aa14ed2032e2c.tar.bz2
rails-dd5cba852fe3a2503bce66530d1aa14ed2032e2c.zip
Extract duplicated `create` and `create!` definition for association
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r--activerecord/lib/active_record/associations/association.rb8
-rw-r--r--activerecord/lib/active_record/associations/collection_association.rb8
-rw-r--r--activerecord/lib/active_record/associations/singular_association.rb8
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?