Jump to:

3373 Posts in 998 Topics by 712 members

Data Model Questions

SilverStripe Forums » Data Model Questions » Modeladmin - not showing fields of managed dataobject

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 1752 Views
  • schellmax
    Avatar
    Community Member
    126 Posts

    Modeladmin - not showing fields of managed dataobject Link to this post

    i was just trying to set up modeladmin on 2.3.2.
    used exactly the code as in the docs (http://doc.silverstripe.org/doku.php?id=modeladmin).

    now, on the 'product' tab to the left, when i click search, in the search results only the fields 'Name' and 'Description' are shown, although the 'Product' class also defines 'Productcode' and 'Prize'. for some reason these fields don't get scaffolded.
    see attached screenshot.

    i also tried managing a new dataobject with the following fields:

       static $db = array(   
          'Headline' => 'Varchar',
          'Teasertext' => 'Text',
          'Fulltext' => 'Text'
       );


    when i view this in my modeladmin, none of the fields are shown, instead only the field 'ID' is used.

    are there some naming limitations on the db fields for objects managed by modeladmin?

    btw. i got dataobjectmanager installed, don't know if this is somehow related.

    anyone else having this problem?

    Attached Files
  • schellmax
    Avatar
    Community Member
    126 Posts

    Re: Modeladmin - not showing fields of managed dataobject Link to this post

    ok, i got there.
    seems i have to define '$summary_fields' on the managed object.
    well, there's some interesting code in the dataobject class which explains why only the 'Name' and 'Description' fields were shown:

          if (!$fields) {
             $fields = array();
             // try to scaffold a couple of usual suspects
             if ($this->hasField('Name')) $fields['Name'] = 'Name';
             if ($this->hasDataBaseField('Title')) $fields['Title'] = 'Title';
             if ($this->hasField('Description')) $fields['Description'] = 'Description';
             if ($this->hasField('FirstName')) $fields['FirstName'] = 'First Name';
          }


    in my opinion, this is an ugly hack. summary_fields should fall back to all available fields instead.

  • Ingo
    Avatar
    Forum Moderator
    801 Posts

    Re: Modeladmin - not showing fields of managed dataobject Link to this post

    > in my opinion, this is an ugly hack. summary_fields should fall back to all available fields instead.

    Summary fields is not only used for a sequential display of fields, but also for table columns in the ModelAdmin result lists. Putting all available fields in there will make the table unuseable. Its a bit of hardcoding magic, but including stuff like "Title" by default seems helpful to avoid requiring specification of summary_fields for simple cases. For scaffolding your search, you should look at $searchable_fields.

  • schellmax
    Avatar
    Community Member
    126 Posts

    Re: Modeladmin - not showing fields of managed dataobject Link to this post

    well, but as mentioned in my initial post, i case you don't have any of those hardcoded fields on you dataobject, only the id is shown in the search result, which makes the table unuseable as well.
    anyway, as there is the possibility to define summary_fields, it's really not much of an issue.
    thanks for your post though

    1752 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.