【发布时间】:2009-07-05 07:35:46
【问题描述】:
我在 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
所以,问题是:如何将出版商连接到图书?这是一对一的关系,整个事情应该是这样的:
p = Book.get(12345).publisher
对不起,也许这是愚蠢的。但我只是不知道我应该使用什么样的声明。
【问题讨论】:
标签: ruby datamapper one-to-one