This project is archived and is in readonly mode.

#6466 new
Bente Pieck

has_many :through, before_destroy is not triggered

Reported by Bente Pieck | February 24th, 2011 @ 04:15 PM

Running rails 3.0.4
My modelstructure is something like:

class Domain < ActiveRecord::Base
  has_many :domain_server_connectors, :dependent => :destroy
  has_many :servers, :through => :domain_server_connectors
end

class Server < ActiveRecord::Base
  has_many :domain_server_connectors, :dependent => :destroy
  has_many :domains, :through => :domain_server_connectors
end

class DomainServerConnector < ActiveRecord::Base
  belongs_to :domain
  belongs_to :server
  before_save :create_something
  before_destroy :destroy_something
end

if I use
@domain.servers << server :create_something will be triggered

@domain.servers.delete server the domain_server_connector between is deleted, but the before_destroy callback :destroy_something is not triggered
the same with @domain.server_ids =
All new ids will trigger :create_something, all missing ids won't trigger :destroy_something (but domain_server_connector will be deleted correctly)

if I use
@domain.domain_server_connectors.delete DomainServerConnector.find_by_domain_id_and_server_id(@domain.id, server.id) the callback is triggered.

I think it should be triggered in both cases, like the before_save-callback is triggered.

No comments found

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

People watching this ticket

Pages