rails 级联删除

大家每天都有一个好心情 :)
  

rails cascade 级联删除[ruby]

 

用一次忘记一次,记下来。

:dependent - if set to :destroy all the associated objects are destroyed alongside this object by calling their destroy method. If set to :delete_all all associated objects are deleted without calling their destroy method. If set to :nullify all associated objects’ foreign keys are set to NULL without calling their save callbacks.

 

 

  1. belongs_to :xxx  
  2. has_many :xxxxs , :foreign_key => :xxxx_id , :dependent => :destroy  
  3. has_many :xxxxs:dependent => :destroy  
2008-10-30 11:27:11--回复文章

原文地址:https://www.cnblogs.com/lexus/p/1887552.html