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.

Customising the CMS /

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

Indexes in DataObject and ModelAdmin


Go to End


3 Posts   2363 Views

Avatar
Vromepiet

Community Member, 11 Posts

8 July 2010 at 7:07am

Hello,

I've just started playing around a bit with silverstripe. As a test, I created a Country class, extending DataObject. I use ModelAdmin to manage these countries. Because I also store the ISO code for a country, I would like to have a unique index on that column. Quite ease so far:

class Country extends DataObject {
 
   static $db = array(
      'Name' => 'Varchar(100)',
      'Description' => 'Varchar(200)',
      'Iso3166' => 'Varchar(10)',
   );
   
   static $indexes = array(
      array( 'type' => 'unique', 'value' => 'Iso3166' )
   );
 
}

However, while testing this new index, I ran into a problem. The ModelAdmin interface does not give any error when I try to enter a country with an already existing ISO code. In fact, it does not do anything. It just keeps displaying the 'saving' animation and nothing else. When I interrupt and go back to the country list, a new EMPTY record seems to be created.

I expected SS to give an error and cancel the Save option. Do I have to program something extra to achieve that behavior?

Jeroen Jansen.

Avatar
Vromepiet

Community Member, 11 Posts

9 July 2010 at 7:34am

Hi,

Problem solved. It seems that in such cases a Validator is required. I'm working on it now.

Regards, Jeroen.

Avatar
ec8or

Community Member, 18 Posts

31 December 2010 at 1:30am

Hi Jeroen,

I am trying to do the exact same thing, have sorted out the index but get no error message in Model Admin. Do you have an example I could have a look at?

Cheers