title: Howto use callbacks in a has_many through association?
body: <p>I have a Task model associated to a Project model via has_many through and need to manipulate the data before delete/insert via the association.</p>
  <p>Since &quot;<a href="https://guides.rubyonrails.org/association_basics.html#the-has-many-through-association" rel="nofollow noreferrer">Automatic deletion of join models is direct, no destroy callbacks are triggered.</a>&quot; i can not use callbacks for this.</p>
  <p>In Task i need all project_ids to calculate a value for Project after Task is saved.
  How can i disable delete or change delete to destroy on has_many through association?
  What is best practise for this problem?</p>
  <pre><code>class Task
    has_many :project_tasks
    has_many :projects, :through =&gt; :project_tasks
  
  class ProjectTask
    belongs_to :project
    belongs_to :task
  
  class Project
    has_many :project_tasks
    has_many :tasks, :through =&gt; :project_tasks
  </code></pre>