Jump to:

5542 Posts in 1739 Topics by 1225 members

Customising the CMS

SilverStripe Forums » Customising the CMS » Indexes in DataObject and ModelAdmin

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

Page: 1
Go to End
Author Topic: 1650 Views
  • Vromepiet
    Avatar
    Community Member
    11 Posts

    Indexes in DataObject and ModelAdmin Link to this post

    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.

  • Vromepiet
    Avatar
    Community Member
    11 Posts

    Re: Indexes in DataObject and ModelAdmin Link to this post

    Hi,

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

    Regards, Jeroen.

  • beezer
    Avatar
    Community Member
    16 Posts

    Re: Indexes in DataObject and ModelAdmin Link to this post

    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

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