mirror of
https://github.com/github/rails.git
synced 2026-04-26 03:00:59 -04:00
Inline ensure_owner_is_persisted! as it is only called from one place
This commit is contained in:
@@ -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?
|
||||
#
|
||||
|
||||
Reference in New Issue
Block a user