Skip to content

Commit a42eda1

Browse files
sobstelp8
andcommitted
doc: Warn against having uniqueness validator when create_or_find_by is used
Co-authored-by: Petrik de Heus <[email protected]>
1 parent 9940dc8 commit a42eda1

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

activerecord/lib/active_record/relation.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,8 @@ def find_or_create_by!(attributes, &block)
255255
# the problem of running out of integers, if the underlying table is still stuck on a primary
256256
# key of type int (note: All \Rails apps since 5.1+ have defaulted to bigint, which is not liable
257257
# to this problem).
258+
# * Columns with unique database constraints should not have uniqueness validations defined,
259+
# otherwise #create will fail due to validation errors and #find_by will never be called.
258260
#
259261
# This method will return a record if all given attributes are covered by unique constraints
260262
# (unless the INSERT -> DELETE -> SELECT race condition is triggered), but if creation was attempted

0 commit comments

Comments
 (0)