phpsilverstripedata-objectsmodeladmin

ModelAdmin screen for DataObject not opening


In SilverStripe 3.1.13 I'm trying to establish a simple one-to-many relationships between DataObjects administrated by ModelAdmin. There is a Facility class that can have one off FacilityCategory.

I can enter the Facility Category tab, but as soon as I enter Facility tab, the "main" screen goes blank, and the admin gets contaminated from then on - no tab would show contents anymore.

I erased all the tables beginning with Facility and FacilityCategories and did dev/build repeatedly with flush.

Would anybody shed some light on me as per why it does not work? What is wrong about my classes/relations?

Facility.php

class Facility extends DataObject {
    private static $db = array(
        'Title' => 'Varchar',
    );

    private static $has_one = array(
        'Category' => 'FacilityCategory'
    );

    public static $summary_fields = array(
        'Title', 'Category'
    );



    public function getCMSFields(){
        $fields = FieldList::create(
            TextField::create('Title'),
            DropdownField::create('FacilityCategoryID', 'Category')
                ->setSource(FacilityCategory::get()->map('ID', 'Title'))
                ->setEmptyString('-- select a category --')
        );
        return $fields;
    }
}

class FacilityAdmin extends ModelAdmin {
    private static $menu_title = 'Facilities';
    private static $url_segment = 'facilities';
    private static $managed_models = array(
        'Facility'
    );
}

FacilityCategory.php

class FacilityCategory extends DataObject {
    private static $db = array(
      'Title' => 'Varchar'
    );

    private static $has_many = array(
      'Facilities' => 'Facility'
    );

    public function getCMSFields(){
        $fields = FieldList::create(
            TextField::create('Title')
        );
        return $fields;
    }
}

class FacilityCategoryAdmin extends ModelAdmin {
    private static $menu_title = 'Facility Categories';
    private static $url_segment = 'facility-categories';
    private static $managed_models = array(
        'FacilityCategory'
    );
}

Solution

  • It could be that in your $summary_fields (which is expected to be private), you have listed the related category object rather than a particular field on the category object, so have:

    private static $summary_fields = array(
      'Title', 
      'Category.Title'
    );