2
好了,我有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
的destroy!
方法在以前的服务器模型中工作,但现在没有做它应该做的。它应该找到与Server
关联的所有Services
,触发Resque
任务(其工作原理),然后销毁Server
及其关联的Services
。
然而,它正在销毁所有ServerServices
(字面上整个表格),而不仅仅是与Server
对象关联的对象,它打破了所有关联。有什么明显的我在这里失踪?