title: How to destroy has_many associations plus join table records?
body: <p>In my Rails app I have these models:</p>
  
  <pre><code>class Person &lt; ActiveRecord::Base
    has_many :jobs
    has_many :projects, :through =&gt; :jobs
  end
  
  class Project &lt; ActiveRecord::Base
    has_many :jobs
    has_many :people, :through =&gt; :jobs
  end
  
  class Job &lt; ActiveRecord::Base
    belongs_to :person
    belongs_to :project
  end
  </code></pre>
  
  <p>When I delete a <code>person</code>, I want to delete all the associated <code>jobs</code> and <code>projects</code>. So I do something like:</p>
  
  <pre><code>class Person &lt; ActiveRecord::Base
    has_many :jobs, :dependent =&gt; :destroy
    has_many :projects, :through =&gt; :jobs, :dependent =&gt; :destroy
  end
  </code></pre>
  
  <p>This works great to get rid of the <code>jobs</code> but leaves the <code>projects</code> (I'm assuming because without the <code>jobs</code>, the <code>person</code> has no way to reference the <code>project</code>). Is there an idiomatic way to do this or do I just need to use a <code>before_destroy</code> callback on my <code>jobs</code> to remove the <code>projects</code>?</p>
  
  <p>Thanks for any help.</p>