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're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

Customising the CMS /

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

Indexes in DataObject and ModelAdmin


Go to End


3 Posts   2095 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