Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

has_many :through, before_destroy is not triggered

#6466

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.

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

State: new
Milestone: none
Assigned to: nobody
Importance: none

Activity

No comments yet.