AR - Delete m:n Associations when deleting Record


I have three tables in my DB

users <–> users_courses <–> courses

users and courses are m:n related:

has_many :courses, :through => :user_courses

has_many :users, :through => :user_courses

I want to delete all records for a user in user_courses when deleting
the user. How do i achieve that?


Take a look at :dependent option in has_many method.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs