This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.
martin21536
Hi, I have found a problem in the processValidationUniqueRule() method of Validation trait. If we make a validation rule "unique" on another table, it doesn't work because the table of the current model is automatically selected:
$table = 'unique:' . $this->getTable();
This line should be replaced by:
$table = $table ?: 'unique:' . $this->getTable();
And after, if the selected table is not the table of the current model, don't add the $key and $keyName params.
Like this:
protected function processValidationUniqueRule($definition, $fieldName)
{
list(
$table,
$column,
$key,
$keyName,
$whereColumn,
$whereValue
) = array_pad(explode(',', $definition), 6, null);
$table = $table ?: 'unique:' . $this->getTable();
$column = $column ?: $fieldName;
$params = [$table, $column];
if($this->getTable() == substr($table, 7)) {
$key = $keyName ? $this->$keyName : $this->getKey();
$keyName = $keyName ?: $this->getKeyName();
}
if ($key) {
$params[] = $key;
}
if ($keyName) {
$params[] = $keyName;
}
if ($whereColumn) {
$params[] = $whereColumn;
}
if ($whereValue) {
$params[] = $whereValue;
}
return implode(',', $params);
}
What do you think ? Thank.
Last updated
1-1 of 1