Skip to content

Instantly share code, notes, and snippets.

@alpaca-tc
Created July 5, 2020 08:47
Show Gist options
  • Save alpaca-tc/c54c8c1492096951d36db251051cae2f to your computer and use it in GitHub Desktop.
Save alpaca-tc/c54c8c1492096951d36db251051cae2f to your computer and use it in GitHub Desktop.
create_or_find_byが動かないケース
# 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