
class Foo < ActiveRecord::Base has_many :bars, dependent: :destroy before_destroy :do_something def do_something return if bars.blank? bars.map &:somethig_cool end end このように, has_many(has_one)な関係をものをbefore_destroyで使うには注意が必要. 上の例だとbefore_destroyの前にbarsは削除されてしまうので, bars.blank?は必ず真になりbars.map &:somethig_coolは永久に実行されない. これを避けるには以下のようにする. class Foo < ActiveRecord::Base before_destroy :do_something has_
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く