我使用 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 设置,在删除 torrent 时我可以:
- 删除标签关联
- 删除种子
当删除标签时,我可以:
- 从具有该标签的所有种子中删除标签关联
- 删除标签
我该怎么办?