user2158382
user2158382

Reputation: 4510

Rails: Dependent delete_all not working

I have 5 models. Server, Platform, Game, RetentionReport, DataReport. And I am trying to use :dependent => :delete_all, but it wont work. Here are my models.

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

Whenever I run Game.delete_all in the terminal, nothing gets deleted not even the Platforms

Upvotes: 1

Views: 1818

Answers (1)

Muntasim
Muntasim

Reputation: 6786

delete_all does not trigger call_backs.

If you have Game.destroy_all it will do what you want.

You can use :dependent => :destroy or :dependent => :delete_all in the association declaration. The former will run callbacks in the association and the later one does not.

Upvotes: 5

Related Questions