我有5個模型。 Server
,Platform
,Game
, RetentionReport
,。我試圖使用:dependent => :delete_all
,但它不會工作。這是我的模特。Rails:依賴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
嘗試'dependent :: destroy'。 – struthersneil
我試過這個和相同的結果 – user2158382
對不起,我是愚蠢的 - 它是'依賴的',而不是'依賴的'。試試:) – struthersneil