假设我们有两个具有多对多关系的模型:
class Tag
  include DataMapper::Resource
  property :id, Serial
  has n, :articles, through: Resource
end
class Article
  include DataMapper::Resource
  property :id, Serial
  has n, :tags, through: Resource
end
现在,如果我创建带有标签的文章:Tag.create(articles: [ Article.create ]) 
如果我Tag.first.delete现在运行,它会返回 false,因为由于多对多关系存在外键约束。如果我运行Tag.first.delete!它会删除标签,但不会删除article_tags表中的关联记录。
如果我使用dm-contraints并将所有内容设置为:destroy它也会破坏不是我想要的文章。
我可以
tag = Tag.first
tag.articles = []
tag.save
tag.destroy
但这似乎不干净。有没有更好的办法?