1

我有5个模型。Server, Platform, Game, RetentionReport, DataReport. 我正在尝试使用:dependent => :delete_all,但它不会工作。这是我的模型。

class Game < ActiveRecord::Base
  attr_accessible :name

  has_many :platforms, :dependent => :delete_all
end

class Platform < ActiveRecord::Base
  attr_accessible :name, :game_id, :company_id

  belongs_to :game
  has_many :servers, :dependent => :delete_all
end

class Server < ActiveRecord::Base
  attr_accessible :name, :region, :device_type, :platform_id, :platform_server_id

  belongs_to :platform
  has_many :gm_data_reports, :dependent => :delete_all
  has_many :gm_retention_reports, :dependent => :delete_all

  delegate :company_id, :to => :platform

  validates :platform_server_id, :uniqueness => {:scope => :platform_id}
end

class DataReport < ActiveRecord::Base

 belongs_to :server
end

class RetentionReport < ActiveRecord::Base

 belongs_to :server
end

每当我Game.delete_all在终端中运行时,都不会删除任何内容,甚至Platforms

4

1 回答 1

5

delete_all不触发call_backs

如果你有Game.destroy_all它会做你想做的事。

您可以在关联声明中使用:dependent => :destroy或。:dependent => :delete_all前者将在关联中运行回调,而后者则不会。

于 2013-10-25T23:50:45.077 回答