Silverstripe $ searchable_fields超过$ has_one,然后是$ many_many关系

时间:2016-05-12 15:51:51

标签: php silverstripe

在Silverstripe V2中,可以创建跨越Obj1.Obj2.Obj3.Obj3Field等关系的可搜索字段,但现在在V3中会产生以下错误......

[User Error] Uncaught LogicException: relation can't be called on an UnsavedRelationList.
GET /zz_silverstripe_default/admin/mymodeladmin/
Line 391 in C:\xampp\htdocs\zz_silverstripe_default\framework\model\UnsavedRelationList.php
Source
390     public function relation() {
391         throw new LogicException(__FUNCTION__ . " can't be called on an UnsavedRelationList.");
392     }
Trace
UnsavedRelationList->relation(EndObject) 
DataObject.php:3009
DataObject->relObject(MiddleDataObjects.EndObject.Name) 
DataObject.php:2285
DataObject->scaffoldSearchFields() 
DataObject.php:2230
DataObject->getDefaultSearchContext() 
ModelAdmin.php:173

重现这个的代码是......

class MyModelAdmin extends ModelAdmin {
    static $managed_models = array('RootDataObject');
    static $url_segment = 'mymodeladmin';
    static $menu_title = 'MyModelAdmin';
    static $model_importers = array();
}

class RootDataObject extends DataObject {
    private static $db = array('Name' => 'Varchar(255)');
    private static $has_many = array('MiddleDataObjects' => 'MiddleDataObject');
    static $searchable_fields = array('MiddleDataObjects.EndObject.Name');
}

class MiddleDataObject extends DataObject {
    private static $db = array('Name' => 'Varchar(255)');
    private static $has_one = array('RootDataObject' => 'RootDataObject');
    private static $many_many = array('EndDataObjects' => 'EndDataObject');
}

class EndDataObject extends DataObject {
    private static $db = array('Name' => 'Varchar(255)');
    private static $belongs_many_many = array('OtherDataObjects' => 'OtherDataObject');
}

我已将此代码上传到http://pastebin.com/QBfU8Fub,其中包含更多空格和一些php标记,以便更轻松地重现此问题。基本上我之前的行为是可行的,所以我不必继续手动编写搜索上下文和过滤器来做一些我对这个漂亮的CMS有所期待的事情。

1 个答案:

答案 0 :(得分:3)

这是SilverStripe框架代码中UnsavedRelationList对象中的错误。

以下是此问题的另一位用户: https://github.com/silverstripe/silverstripe-widgets/issues/123

有一个解决方法: https://github.com/silverstripe/silverstripe-framework/pull/5348

但是,在SilverStripe 3.4 / SilverStripe 4.0之前不会发布此更新。