Я следующий сценарийРельсы уничтожить все Вложенные ассоциации
class Company < ActiveRecord::Base
has_many :depots, inverse_of: :company, :dependent => :destroy
has_many :users, inverse_of: :company, :dependent => :destroy
has_many :products
end
class Depot < ActiveRecord::Base
has_many :products, :dependent => :destroy
has_many :zones, :dependent => :destroy
belongs_to :company
end
class Product < ActiveRecord::Base
belongs_to :depot
belongs_to :company
end
class Zone < ActiveRecord::Base
belongs_to :depot
end
class User < ActiveRecord::Base
belongs_to :company, , inverse_of: :users
end
## and zone has_many locations which further has some associated models.
Я хочу, чтобы удалить все связанные модели с компанией, не называя их по одному. Мой зависимый истребитель не работает, и когда я пытаюсь удалить компанию, продукты все еще там. Я пробовал заменить
dependent: :destroy #to delete_all
но не повезло. Как я могу удалить все вложенные объекты с помощью одного вызова destroy для компании?
Редактировать
Я могу назвать
Company.reflect_on_all_associations(:has_many)
и удалить все ассоциации по одному, но я не хочу, чтобы пойти на этот подход. Любая помощь??
Пожалуйста, опубликуйте результат следующего запроса MySQL: «SHOW CREATE TABLE companies» – Bustikiller
извините, я использую Postgres как свою БД. –