DataMapper: one to many relationship with one of several models?

Here's my models: class Item include DataMapper::Resource property :id, Serial has 1, :firstitem has 1, :seconditem end class FirstItem include DataMapper::Resource property :id, Serial belongs_to :item end class SecondItem include DataMapper::Resource property :id, Serial belongs_to :item end Now, my question is this - if I want `FirstItem` and `SecondItem` to be different models but want them both to potentially be part of `Item` (but only one of the two, so a record with `FirstItem` will not also have a `SecondItem`), I could make a `has 1` relationship for both of them, and only one of them gets filled. So in a relational database, does it make sense to do this? Is there a better, more efficient way of defining this relationship?

以上就是DataMapper: one to many relationship with one of several models?的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » WebStorm

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准

联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏