我有这个带有 Torrent 和 Tag 的很多 DataMapper/MySQL 设置,如下所示:
class Torrent
include DataMapper::Resource
property :id, Serial
property :name, String
property :magnet, Text
property :created_at, DateTime
has n, :tags, :through => Resource
end
class Tag
include DataMapper::Resource
property :id, Serial
property :name, String
property :hits, Integer
has n, :torrents, :through => Resource
end
但是,当尝试通过Torrent.first.destroy
或类似的方式销毁种子时,DataMapper 会返回false
.
我尝试了类似的直接 SQL 查询delete from torrents where name like '%ubuntu%'
,但由于 MySQL 错误 1451 而失败:
ERROR 1451 (23000): Cannot delete or update a parent row: a foreign key constraint fails (`brightswipe`.`tag_torrents`, CONSTRAINT `tag_torrents_torrent_fk` FOREIGN KEY (`torrent_id`) REFERENCES `torrents` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION)
我认为有一些 DataMapper 设置,在删除种子时我可以:
- 删除标签关联
- 删除种子
删除标签时,我可以:
- 从具有该标签的所有种子中删除标签关联
- 删除标签
我该怎么办?