【问题标题】:DataMapper: Putting a model into a modelDataMapper:将模型放入模型中
【发布时间】:2011-01-16 23:35:51
【问题描述】:

DataMapper documentation for associations 中,我找到了一个示例,他们将模型放入...

 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   ...

它对您返回的结果有任何影响吗?还是只是另一种表示法或格式?

提前致谢,鲁弗斯

【问题讨论】:

    标签: sinatra datamapper


    【解决方案1】:

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

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

    【讨论】:

    • 感谢您的快速回答!
    猜你喜欢
    • 1970-01-01
    • 2023-03-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多