Inline ensure_owner_is_persisted! as it is only called from one place

This commit is contained in:
Jon Leighton
2011-02-14 01:19:42 +00:00
parent c9b685e681
commit 5d6d669bfe

View File

@@ -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?
#