0
0

More than 1 year has passed since last update.

値がnilになる可能性があるか調べたい

Posted at

ある値がnilになる可能性があるか知りたい時

レビューをしてもらっていると、
「これってnilになる可能性ありますか?」と聞かれることがある。
突然の質問に、困惑したのでその調べ方を残しておく。

schema.rbを確認する

ここにはDBの制約が書かれているので
知りたい値に null: false があればdbにnullが許容されないということがわかる。

modelを確認する

ここにはmodelのバリデーションが書かれているので
知りたい値にexclusion: { in: [nil] }とか定義してあればnullが許容されないということがわかる。

おわり

よきコードを書きたい。

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