Adds a new Unique index to the list of unique indices and set the
parent table of the column to the current table.

@param  Unique|array $unique
@return Unique
336816
public function addUnique($unique)
    {
        if ($unique instanceof Unique) {
            $unique->setTable($this);
            $unique->getName(); // we call this method so that the name is created now if it doesn't already exist.
            $this->unices[] = $unique;

            return $unique;
        }

        $unik = new Unique();
        $unik->loadMapping($unique);

        return $this->addUnique($unik);
    }
918365
protected function addUniqueConstraint(Table $table)
    {
        $unique = new Unique($this->getColumnForParameter('slug_column'));
        $unique->setName($table->getCommonName() . '_slug');
        $unique->addColumn($table->getColumn($this->getParameter('slug_column')));
        if ($this->getParameter('scope_column')) {
            $unique->addColumn($table->getColumn($this->getParameter('scope_column')));
        }
        $table->addUnique($unique);
    }
1198933
public function setFromADOIndex($adoindex) {

        // Set the unique field
        $this->unique = false;
        // Set the fields, converting all them to lowercase
        $fields = array_flip(array_change_key_case(array_flip($adoindex['columns'])));
        $this->fields = $fields;
        // Some more fields
        $this->loaded = true;
        $this->changed = true;
    }
1029396
final public function distinct($column)
    {
        if (!is_array($column)) {
            $column = explode(',', $column);
        }
        $column = array_map([$this, 'formatColumn'], $column);

        $this->_sql['distinct'] = array_merge($this->_sql['distinct'], $column);
        return $this;
    }
453834
public function distinct($distinct = true)
    {
        foreach ($this->queries as $query) {
            $query->distinct($distinct);
        }

        return $this;
    }
969208
public function distinct($distinct=null)
    {
        $distinct = LambdaUtils::toSelectCallable($distinct);

        $keys = array();
        $collection = $this->newInstance();
        foreach($this as $record)
        {
            $value = call_user_func($distinct, $record);
            $hash = md5(json_encode($value));
            if(!isset($keys[$hash]))
            {
                $keys[$hash]=true;
                $collection->add($record);
            }
        }
        return $collection;
    }
1071530
public function uniqueKeepIndex(): self
    {
        // INFO: \array_unique() can't handle e.g. "stdClass"-values in an array

        // init
        $array = $this->getArray();

        $this->array = \array_reduce(
            \array_keys($array),
            static function ($resultArray, $key) use ($array) {
                if (!\in_array($array[$key], $resultArray, true)) {
                    $resultArray[$key] = $array[$key];
                }

                return $resultArray;
            },
            []
        );
        $this->generator = null;

        if ($this->array === null) {
            $this->array = [];
        } else {
            $this->array = (array) $this->array;
        }

        return $this;
    }
202224
public function createIndex(array $columnNames, $unique = false, $name = null)
    {
        $index = new Index($name, $columnNames, $unique);
        $this->addIndex($index);

        return $index;
    }
229231
public function addIndex($columns, $unique = FALSE, $length = 20)
    {
        if (!is_array($columns))
            $columns = array($columns);
        $cols = $this->columns;
        foreach ($cols as &$col)
            $col = $col->getColumnArray();
        parent::_addIndex($columns,$cols,$unique,$length);
    }
319406
public function setUniqueKey($uniqueKey)
    {
        if (! is_null($this->uniqueKey)) {
            throw new RuntimeException('The unique key was already set.');
        }
        if (! is_int($uniqueKey) && ! is_string($uniqueKey)) {
            throw new InvalidArgumentException(sprintf(
                'Invalid type of specified unique key; must be an integer or '
                . 'an string, "%s" received.',
                gettype($uniqueKey)
            ));
        }
        $this->uniqueKey = $uniqueKey;
    }
317006
public function unique(bool $unique = true): AbstractIndex
    {
        $this->type = $unique ? self::UNIQUE : self::NORMAL;

        return $this;
    }
411857
public function addUniqueKey($name, array $fields)
    {
        //Argument 1 must be a string
        Argument::i()->test(1, 'string');
        
        $this->uniqueKeys[$name] = $fields;
        return $this;
    }
1162058
public function addIndex($indexName) {
    if (is_array($indexName)) {
      $this->indexes = $indexName;
    } else {
      $this->indexes[] = $indexName;
    }
    $this->indexes = array_unique($this->indexes);
  }
447588
public function reduce_dimension(bool $unique = true): self
    {
        // init
        $result = [[]];

        foreach ($this->getGenerator() as $val) {
            if (\is_array($val)) {
                $result[] = (new self($val))->reduce_dimension($unique)->getArray();
            } else {
                $result[] = [$val];
            }
        }
        $result = \array_merge(...$result);

        $resultArrayy = new self($result);

        return $unique ? $resultArrayy->unique() : $resultArrayy;
    }
1118393
public function setDistinct($distinct = true)
    {
        $this->distinct = $distinct;
        $this->queryBuilder->distinct($distinct);
        return $this;
    }
1261785
public function unique(array $columns, string $message = null)
    {
        $this->initializeUniqueValidator($message);
        $this->unique = $columns;

        return $this;
    }
1114896
private static function other($column, array $unique)
    {
        $definition = '';

        // size
        if (null !== $column->scale && 0 < $column->scale) {
            $definition .= "($column->precision,$column->scale)";

        } elseif (null !== $column->size && !$column->autoIncrement && 'tinyint(1)' !== $column->dbType) {
            $definition .= "($column->size)";

        } elseif (null !== $column->size && !$column->isPrimaryKey && $column->unsigned) {
            $definition .= "($column->size)";
        }

        // unsigned
        if ($column->unsigned) {
            $definition .= '->unsigned()';
        }

        // null
        if ($column->allowNull) {
            $definition .= '->null()';

        } elseif (!$column->autoIncrement) {
            $definition .= '->notNull()';
        }

        // unique key
        if (!$column->isPrimaryKey && !empty($unique)) {
            foreach ($unique as $name) {
                if (reset($name) === $column->name) {
                    $definition .= '->unique()';
                }
            }
        }

        // default value
        if ($column->defaultValue instanceof Expression) {
            $definition .= "->defaultExpression('$column->defaultValue')";

        } elseif (is_int($column->defaultValue)) {
            $definition .= "->defaultValue($column->defaultValue)";

        } elseif (is_bool($column->defaultValue)) {
            $definition .= '->defaultValue('.var_export($column->defaultValue, true).')';

        } elseif (is_string($column->defaultValue)) {
            $definition .= "->defaultValue('".addslashes($column->defaultValue)."')";
        }

        // comment
        if (null !== $column->comment && '' !== $column->comment) {
            $definition .= "->comment('".addslashes($column->comment)."')";
        }

        // append

        return $definition;
    }