gpt4 book ai didi

ruby-on-rails - rails : Dependent delete_all not working

转载 作者:太空宇宙 更新时间:2023-11-03 17:35:04 25 4
gpt4 key购买 nike

我有 5 个模型。 服务器平台游戏RetentionReportDataReport。我正在尝试使用 :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

最佳答案

delete_all 不会触发 call_backs

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

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

关于ruby-on-rails - rails : Dependent delete_all not working,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19600643/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com