I'm building a plugin that has a column in the DB which is unique
and essentially an AttributeType::Handle
.
Here is the piece from the record:
return array(
'key' => array(AttributeType::Handle, 'default' => '', 'required' => true),
);
And in my service after the $model
has passed validation:
if ($record->save()) {
// update id on model (for new records)
$model->setAttribute('id', $record->getAttribute('id'));
return true;
} else {
$model->addErrors($record->getErrors());
return false;
}
When does that handle validation happen? If I pass something that wouldn't pass handle validation (spaces or a reserved word), it doesn't save the record in the database, but it doesn't throw any errors.
In addition, is there a way to throw an error when the value isn't unique? Again, the record doesn't save if I use a key that is already in the DB, but there is no error.
Happy to provide more code if necessary, just didn't want to overcomplicate the question. Thanks!