我正在使用datamapper制作博客服务,并定义了文章和标签模型,如下所示。
class Article
include DataMapper::Resource
property :id, Serial
has n, :tags, :through => Resource
end
class Tag
include DataMapper::Resource
property :id, Serial
has n, :articles, :through => Resource
end
这些关系在'article_tags'表中定义。
答案 0 :(得分:1)
class Tag
include DataMapper::Resource
property :id, Serial
has n, :articles, 'Article',:child_key => [:article_id]
end