FIX: destroy CategoryGroup when Category or Group is destroyed

This commit is contained in:
Kamil Bielawski
2014-08-31 22:10:38 +02:00
parent 5c244c6f8f
commit bf679f1626
3 changed files with 15 additions and 2 deletions

View File

@ -0,0 +1,13 @@
class RemoveCategoryGroupsOrphanedByRemovingCategoryOrGroup < ActiveRecord::Migration
def up
execute "DELETE FROM category_groups
WHERE group_id NOT IN (
SELECT groups.id FROM groups)
OR category_id NOT IN (
SELECT categories.id FROM categories)"
end
def down
raise ActiveRecord::IrreversibleMigration
end
end