aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorJon Leighton <j@jonathanleighton.com>2011-02-14 01:19:42 +0000
committerJon Leighton <j@jonathanleighton.com>2011-02-14 01:40:31 +0000
commit5d6d669bfe1e480dd4d0cc5042b7faba4b469846 (patch)
tree27536346c72a5fe18db1a3f5da69c43ac4ac304a /activerecord/lib
parentc9b685e681ea5851c2baaaec780fcc9c6a9e2775 (diff)
downloadrails-5d6d669bfe1e480dd4d0cc5042b7faba4b469846.tar.gz
rails-5d6d669bfe1e480dd4d0cc5042b7faba4b469846.tar.bz2
rails-5d6d669bfe1e480dd4d0cc5042b7faba4b469846.zip
Inline ensure_owner_is_persisted! as it is only called from one place
Diffstat (limited to 'activerecord/lib')
-rw-r--r--activerecord/lib/active_record/associations/association_collection.rb12
1 files changed, 4 insertions, 8 deletions
diff --git a/activerecord/lib/active_record/associations/association_collection.rb b/activerecord/lib/active_record/associations/association_collection.rb
index 8b5e600c96..888ebdf7af 100644
--- a/activerecord/lib/active_record/associations/association_collection.rb
+++ b/activerecord/lib/active_record/associations/association_collection.rb
@@ -67,11 +67,13 @@ module ActiveRecord
end
def create(attributes = {})
+ unless @owner.persisted?
+ raise ActiveRecord::RecordNotSaved, "You cannot call create unless the parent is saved"
+ end
+
if attributes.is_a?(Array)
attributes.collect { |attr| create(attr) }
else
- ensure_owner_is_persisted!
-
transaction do
add_to_target(build_record(attributes)) do |record|
yield(record) if block_given?
@@ -471,12 +473,6 @@ module ActiveRecord
@owner.class.send(full_callback_name.to_sym) || []
end
- def ensure_owner_is_persisted!
- unless @owner.persisted?
- raise ActiveRecord::RecordNotSaved, "You cannot call create unless the parent is saved"
- end
- end
-
# Should we deal with assoc.first or assoc.last by issuing an independent query to
# the database, or by getting the target, and then taking the first/last item from that?
#