わかりましたので、関係を持つ2つのモデルがありますhas_many :through:
class Server < ActiveRecord::Base
has_many :services, :through :servers_services, :dependent => :destroy
has_many :servers_services, :dependent => :destroy
def destroy!
options = {:name => self.name, :services => self.services.map { |s| s.attributes }}
Resque.enqueue(Cluster::DestroyServer, options)
self.destroy
end
end
と
class Service
has_many :servers, :through => :servers_services
has_many :servers_services
end
これらは次の方法で接続されています。
class ServersService < ActiveRecord::Base
belongs_to :server
belongs_to :service
end
Server モデルのdestroy!メソッドは以前は機能していましたが、現在は機能していません。Servicesに関連付けられているすべてを見つけてServer、タスクをトリガーし(これは機能します)、とそれに関連付けられResqueている を破棄します。ServerServices
ただし、オブジェクトにServerServices関連付けられているものだけでなく、すべて (文字通りテーブル全体) を破棄すると、すべての関連付けが解除されます。Serverここで私が見逃している明らかなものはありますか?