Merge pull request #42625 from intrip/36027-create-or-find-by-docs
Adjust docs of create_or_find_by
This commit is contained in:
commit
c3fe14c239
@ -182,7 +182,7 @@ def find_or_create_by!(attributes, &block)
|
||||
find_by(attributes) || create!(attributes, &block)
|
||||
end
|
||||
|
||||
# Attempts to create a record with the given attributes in a table that has a unique constraint
|
||||
# Attempts to create a record with the given attributes in a table that has a unique database constraint
|
||||
# on one or several of its columns. If a row already exists with one or several of these
|
||||
# unique constraints, the exception such an insertion would normally raise is caught,
|
||||
# and the existing record with those attributes is found using #find_by!.
|
||||
@ -193,7 +193,7 @@ def find_or_create_by!(attributes, &block)
|
||||
#
|
||||
# There are several drawbacks to #create_or_find_by, though:
|
||||
#
|
||||
# * The underlying table must have the relevant columns defined with unique constraints.
|
||||
# * The underlying table must have the relevant columns defined with unique database constraints.
|
||||
# * A unique constraint violation may be triggered by only one, or at least less than all,
|
||||
# of the given attributes. This means that the subsequent #find_by! may fail to find a
|
||||
# matching record, which will then raise an <tt>ActiveRecord::RecordNotFound</tt> exception,
|
||||
|
Loading…
Reference in New Issue
Block a user