jeudi 2 mars 2017

before_destroy not firing with has_many :through

I want to delete all record of group_maps that is associated with the group of it. In the docs, its saying

If the :through option is used, then the join records are destroyed instead, not the objects themselves.

Im confused.

group.rb

class Group < ApplicationRecord

  belongs_to :user

  has_many :group_maps
  has_many :users, :through => :group_maps

  before_destroy :destroy_group_maps

  def destroy_group_maps
    self.group_maps.delete_all
  end

end

rails c output

Aucun commentaire:

Enregistrer un commentaire