かみぽわーる

kamipo's blog

ツイッターで見つけて直したActiveRecordの問題3つ

Rails Advent Calendar 2020の3日目です。

時間がないのでとりいそぎ3つだけ。

  • enum state: {active: 0, inactive: 1}とかした時に、typecast前の0とか1を取りたい

github.com

  • belongs_to :author, class_name: 'User'したときにleft_joins(:author).where("author.id": nil)とか書きたい

github.com

  • attributeでDBの型情報を保ったままdefault値だけ定義したい

github.com