![Loading...](https://cdn-ak-scissors.b.st-hatena.com/image/square/240a6b0f47faffc53d88110037e035708b64f51d/height=288;version=1;width=512/http%3A%2F%2Fhonda-3d.com%2Fshare.jpg)
Active Record Callbacks Callbacks are hooks into the life cycle of an Active Record object that allow you to trigger logic before or after a change in the object state. This can be used to make sure that associated and dependent objects are deleted when ActiveRecord::Base#destroy is called (by overwriting before_destroy) or to massage attributes before they’re validated (by overwriting before_vali
正確にはRailsというよりもActiveRecordでの設定ですが、 ささたつ(@sasata299)さんがhas_many のdependentオプションについて書かれていたので便乗エントリー。 参照先のデータを削除したときに、参照元のデータも削除して整合性を保つ ActiveRecordのテーブル間のレーションを指定するhas_manyとhas_oneの:dependentオプションを適切なものに指定してあげるだけ。 このdependentオプションで1番有名なのは:destroyオプションです。 親を削除すると子も削除されるというやつですね。 が、それ以外にも便利な:dependentオプションがあるのでまとめてみました。 :dependentオプションについて :dependentオプションは削除するレコードに関連するレコードの取り扱いを指定するためのオプション
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く