具有麻烦的DataMapper关联模型我真的。它很简单,但我可以明白我的意思。

所以,我有2个表:

1. Books
-> id
-> title
-> publisher_id

2. Publishers
-> id
-> title

在类:

class Book
  property :id, Serial
  property :title, String
  property :publisher_id, Integer
end

class Publisher
  property :id, Serial
  property :title, String
end

所以,问题是:如何能连接出版商的书?它是1对1的关系,并且应该看起来像这样整个事情:

p = Book.get(12345).publisher

对不起,也许这是愚蠢的。但我只是无法弄清楚我应该用什么样的声明。

没有正确的解决方案

其他提示

哈哈,即时通讯疯狂白痴在早上坐在2。总是发生在我身上,当我问somethis - 突然发现我自己的问题的答案

它不正确,有一对多的关系。因此,它是简单的太阳在天空中:

class Book
  property :id, Serial
  property :title, String
  property :publisher_id, Integer

  belongs_to :publisher
end

class Publisher
  property :id, Serial
  property :title, String

  has n, :books
end

That`s它。这可能是有帮助的人。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top