Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Data Model Questions /

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

Modeladmin - not showing fields of managed dataobject


Go to End


4 Posts   2953 Views

Avatar
schellmax

Community Member, 126 Posts

11 July 2009 at 5:15am

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
Avatar
schellmax

Community Member, 126 Posts

11 July 2009 at 8:23pm

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.

Avatar
Ingo

Forum Moderator, 801 Posts

14 July 2009 at 8:31am

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

Avatar
schellmax

Community Member, 126 Posts

14 July 2009 at 7:39pm

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