关联表级联删除

Mysql2::Error: Cannot delete or update a parent row: a foreign key constraint fails (`todo_list_development`.`todo_items`, CONSTRAINT `fk_rails_d913ce1c56` FOREIGN KEY (`todo_list_id`) REFERENCES `todo_lists` (`id`)): DELETE FROM `todo_lists` WHERE `todo_lists`.`id` = 4

http://api.rubyonrails.org/

class Post < ActiveRecord::Base
  # because we store "Post" in attachable_type now dependent: :destroy will work
  has_many :assets, as: :attachable, dependent: :destroy
end

 

posted @ 2016-04-19 09:51  冰凌花花~  阅读(152)  评论(0编辑  收藏  举报