Cascade delete model in rails -
class car < activerecord::base end class city < activerecord::base has_many :cars_available, dependent: :destroy end class carsavailable < activerecord::base belongs_to :car belongs_to :city end
i have 2 models car , city, , third model carsavailable stores particular cars available in particular city.
how set destroy association between car , carsavailable when car removed corresponding carsavailable entry deleted.
i figured out city little ambiguous how apply car.
this trick:
class car < activerecord::base has_many :cars_available, dependent: :destroy end
add association car
, tell destroy association, did city
.
Comments
Post a Comment