关联表级联删除



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/  搜索has_many


class Post < ActiveRecord::Base
  # because we store "Post" in attachable_type now dependent: :destroy will work
  has_many :assets, as: :attachable, <span style="background-color: rgb(255, 0, 0);">dependent: :destroy</span>
end



你可能感兴趣的:(关联表级联删除)