0
0

Rails - データベースの既存レコードからバリデーションエラーのデータを探す方法

Last updated at Posted at 2024-06-08

概要

Rails的にはバリデーション違反なのだが、いちどデータベースにレコードが記録されてしまい、そのまま残っているデータがあるという場合がある

それを見つける方法

単に instance.validate するだけで良い

コード例

examines テーブルの全てのレコードのバリデーション違反状態を確認する例

Example.all.each do |example|
  example.validate

  if example.errors.present?
    p example.errors.full_messages
  end
end

チャットメンバー募集

何か質問、悩み事、相談などあればLINEオープンチャットもご利用ください。

プロフィール・経歴

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0