/** * @param \ORM\Model $record * @return bool|mixed */ function validate(\ORM\Model $record) { $class_name = $record::className(); if ($record->isPersisted()) { return count($class_name::where($this->field . " = ? AND " . $class_name::getPrimaryKey() . " != ?", [$record->{$this->field}, $record->{$class_name::getPrimaryKey()}])) === 0; } else { return count($class_name::where($this->field . " = ?", [$record->{$this->field}])) === 0; } }