There is an Entity\Validator\Unique class for checking for uniqueness. Only he checks the uniqueness of a particular field. How to check if I have a unique key created from two fields unique ux_table_name (PROPERTY_ID, XML_ID) when creating a table?
1 answer
In general, I understand there is no way. Therefore, we create a table using an SQL query from the install file, and then do something like
new Entity\StringField('YOUR_FIELD_CODE', array( 'required' => true, 'validation' => array(__CLASS__, 'validateFunction'), 'title' => Loc::getMessage('YOUR_FIELD_CODE_FIELD'), ) ), and manually do the validation
public static function validateFunction() { return array( function ($value, $primary, $row, $field) { $error_message = Loc::getMessage('ENUM_ENTITY_DUPLICATE_ERROR'); if($bad_val)//не прошли валидацию return new Entity\FieldError($field, $error_message, 'UNIQUE_CHECK'); else return true; }, new Main\Entity\Validator\Length(null, 200), ); } |