Created
July 5, 2020 08:47
-
-
Save alpaca-tc/c54c8c1492096951d36db251051cae2f to your computer and use it in GitHub Desktop.
create_or_find_byが動かないケース
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# create_table :users do |t| | |
# t.integer :uuid, null: false | |
# t.index :uuid, unique: true | |
# end | |
class User < ApplicationRecord; end | |
User.transaction do | |
User.find_by(uuid: 1) #=> nil | |
# ここで別transactionにて | |
# User.create!(uuid: 1) | |
User.create_or_find_by!(uuid: 1) #=> ActiveRecord::RecordNotFound | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment