【问题标题】:Silverstripe 3.1 page has_one belongs_many dataobjectSilverstripe 3.1 页面 has_one 属于_many 数据对象
【发布时间】:2015-03-23 09:40:36
【问题描述】:

我有一个class ProductPage extends Page 和一个class ProductSpecifications extends DataObject。我可以创建与 Dataobject 的 $has_one 关系和返回 ProductPage 的 $belongs_to 吗? (我知道将所有数据与页面相关联更容易,但我更喜欢 ProductSpecifications 作为单独的数据对象)。如果是这样,我如何从页面访问数据对象的 CMS 字段?格子场?或者类似

$fieldsToAdd = ProductSpecifications::create();
$fieldsToAdd->getCMSFields();
$fields->addFieldsToTab('Root.Specifications', $fieldsToAdd);

【问题讨论】:

    标签: silverstripe


    【解决方案1】:

    您是在说 1:1 的关系?那么问题的标题有点误导。

    您可以使用 has one edit module 编辑 has_one “内联”

    希望对你有帮助,wmk

    【讨论】:

    • 是的,一对一的关系。回到 ProductPage 的 $belongs_to 是否管理关系,还是没有必要?
    • 1:1 一方面是 $has_one,另一方面是 $belongs_to。这样您就可以从相关的 Specifications DataObject 来到您的主 ProductPage。如果你不需要它可能是不必要的,但如果你把它留在里面会更正确/更优雅。你试过 HasOneEdit 模块吗?
    猜你喜欢
    • 1970-01-01
    • 2016-10-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多