ruby on rails - Difference between :destroy and :delete for :dependent in has_one association -


this question has answer here:

in rails document active record associations, first 2 values of :dependent has_one are:

4.2.2.4 :dependent  controls happens associated object when owner destroyed:      :destroy causes associated object destroyed     :delete causes associated object deleted directly database (so callbacks not execute) 

my understanding :destroy example, customer has_one address. :dependent => :destroy, if customer deleted, address deleted automatically database after customer deleted database , use :destroy. what's use of :delete?

both same, said almost, because:

dependent: :destroy - calls callbacks (before_destroy, after_destroy) in associated objects, , you're able break transactions (raise error in callback).

dependent: :delete - doesn't call callbacks (it removes object directly database sql delete ... ...)


Comments

Popular posts from this blog

Android : Making Listview full screen -

javascript - Parse JSON from the body of the POST -

javascript - How to Hide Date Menu from Datepicker in yii2 -