AttributeType::Handle Validation and Unique
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.


If you use 'unique' =&gt; true in an attribute on your record, Craft will use Yii's CUniqueValidator class to verify the uniqueness of an attribute in the database.

$record-&gt;validate() will fail and you can use $record-&gt;getErrors() to get the error message.

return array(
    'key' =&gt; array(AttributeType::Handle, 'default' =&gt; '', 'required' =&gt; true, 'unique' =&gt; true),
);