次のように、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 からタグの関連付けを削除します
- タグを削除する
これについてどうすればいいですか?