Fix bug, when ':dependent => :destroy' violates foreign key constraints

Fix issue, when ':dependent => :destroy' option violates foreign key constraints, issue #12380