1
0

More than 1 year has passed since last update.

【Rails】ActiveStorageはdependent: :destroyをつけなくてもよい

Posted at

環境

Rails 6.0.1
Ruby 2.6.3
PostgreSQL 11.16

has_one_attachedにオプションは不要

app/models/user.rb
has_one_attached :avatar

If the :dependent option isn't set, the attachment will be purged (i.e. destroyed) whenever the record is destroyed.

has_one_attached :avatar, dependent: :destroy

のようにオプションつけなくても、親モデルが削除されたら付随するavatarも削除してくれる!

1
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
1
0