mirror of
https://github.com/lucaspalomodevelop/core.git
synced 2026-03-17 01:54:49 +00:00
MVC: Add allowEmpty option to UniqueConstraint
This is useful in cases where "empty" has special meaning, but is allowed to occur multiple times, while any set value still has to adhere to the unique constraint.
This commit is contained in:
parent
720216f10e
commit
0b6317accb
@ -45,9 +45,18 @@ class UniqueConstraint extends BaseConstraint
|
||||
*/
|
||||
public function validate($validator, $attribute): bool
|
||||
{
|
||||
$allowEmpty = ($this->getOption('allowEmpty') === 'Y') ? true : false;
|
||||
if ($allowEmpty && !empty($this->getOptionValueList('addFields'))) {
|
||||
throw new \Exception('UniqueConstraint allowEmpty and addFields cannot be used in tandem');
|
||||
}
|
||||
|
||||
$node = $this->getOption('node');
|
||||
$fieldSeparator = chr(10) . chr(0);
|
||||
if ($node) {
|
||||
if ($allowEmpty && empty((string)$node)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$containerNode = $node;
|
||||
$nodeName = $node->getInternalXMLTagName();
|
||||
$parentNode = $node->getParentNode();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user