The Man The Man - 8 months ago 54
SQL Question

Silverstripe duplicate entries even with unique index

I'm trying to prevent duplicate records when adding customer records in my crm with the following index,

private static $indexes = array(
'IndexFirstSurName' => array(
'type' => 'unique',
'value' => '"FirstName","Surname"'

note that I extended Customer from Member were FirstName and Surname came from

class Customer extends Member

But Silverstripe is still allowing duplicate entries of FirstNane and Surname combination? Anyone experienced the same?


The Man, in my experience a validate() is still needed even when using indexing:

public function validate() {
    $result = parent::validate();

    if(Member::get()->filter(array('FirstName' => $this->FirstName, 'Surname' => $this->Surname))->first()) {
        $result->error('First and Surname must be unique for each member.');

    return $result;