DataMapper:将模型放入模型中

发布于 2024-10-12 11:01:47 字数 680 浏览 2 评论 0原文

关联的DataMapper文档中,我找到了一个示例,他们将模型放入模型中,例如

 1 class Person
 2 
 3   class Link
 4 
 5     include DataMapper::Resource
 6 
 7     storage_names[:default] = 'people_links'
 8 
 9     # the person who is following someone
10     belongs_to :follower, 'Person', :key => true
11 
12     # the person who is followed by someone
13     belongs_to :followed, 'Person', :key => true
14 
15   end
16 
17   include DataMapper::Resource
18 
19   property :id,   Serial
20   property :name, String, :required => true
21   ...

......它对您返回的结果有任何影响还是只是另一种符号或格式?

预先感谢,鲁弗斯

In the DataMapper documentation for associations I found an example where they put a model into a model like...

 1 class Person
 2 
 3   class Link
 4 
 5     include DataMapper::Resource
 6 
 7     storage_names[:default] = 'people_links'
 8 
 9     # the person who is following someone
10     belongs_to :follower, 'Person', :key => true
11 
12     # the person who is followed by someone
13     belongs_to :followed, 'Person', :key => true
14 
15   end
16 
17   include DataMapper::Resource
18 
19   property :id,   Serial
20   property :name, String, :required => true
21   ...

Does it have any influence on the result you get back or is it just another notation or format?

Thanks in advance, rufus

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

月亮邮递员 2024-10-19 11:01:47

不,它对结果没有任何影响。

如果将模型放在命名空间中,它会反映在存储名称中。这就是为什么在上面的示例中您会在 Link 模型中看到“storage_names[:default] = 'people_links'”,因为该模型位于 Person 命名空间内,这反映在“people_links”表名称中。

No, it doesn't have any influence on the result.

If you put your models in a namespace it will reflect in storage names though. That's why in the example above you see "storage_names[:default] = 'people_links'" in Link model, because that model is inside Person namespace, which is reflected in "people_links" table name.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文