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

Popular posts from this blog

AbotX : How do you create a parallel crawler that stays on and can be added to at run time from new requests -

testing - Detect whether test has failed within fixture -

android - Create single AAR file from multiple modules using Gradle -