Skip to content

Commit

Permalink
Merge pull request rails#51049 from sobstel/main
Browse files Browse the repository at this point in the history
[DOCS] Warn against uniqueness validator when create_or_find_by is used [ci-skip]
  • Loading branch information
p8 authored Feb 13, 2024
2 parents e4f1c87 + a42eda1 commit a42ca9c
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions activerecord/lib/active_record/relation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,8 @@ def find_or_create_by!(attributes, &block)
# the problem of running out of integers, if the underlying table is still stuck on a primary
# key of type int (note: All \Rails apps since 5.1+ have defaulted to bigint, which is not liable
# to this problem).
# * Columns with unique database constraints should not have uniqueness validations defined,
# otherwise #create will fail due to validation errors and #find_by will never be called.
#
# This method will return a record if all given attributes are covered by unique constraints
# (unless the INSERT -> DELETE -> SELECT race condition is triggered), but if creation was attempted
Expand Down

0 comments on commit a42ca9c

Please sign in to comment.