@param string $inverseKey
@param string $references
@param bool   $unique

@return $this
353805
public function target($inverseKey, $references = 'id', $unique = false)
    {
        return $this->inverseKey($inverseKey, $references, $unique);
    }
768134
public function remove($reference)
    {
        $reference = $this->computeKeyFQN($reference);
        $matcher = $this->getMatcher();

        Collection::cast(self::$data)->each(function (&$value, $key) use ($matcher, $reference) {
            if ($matcher->match($reference, $key)) {
                unset(self::$data[$key]);
            }
        });
        return $this;
    }
1275462
public function references($references)
    {
        if (null !== $references && !is_array($references)) {
            throw new \InvalidArgumentException(sprintf('The references "%s" are not valid.', $references));
        }

        $this->references = $references;

        return $this;
    }
1353289
public function setTransactionReference($reference)
    {
        if (strpos($reference, 'SecurityKey') !== false) {
            // A JSON string provided - the legacy transactionReference format.
            // Decode it then extact the securityKey.
            // We only need the security key here for the signature; all other
            // items from the reference will be in the server request.

            $parts = json_decode($reference, true);

            if (isset($parts['SecurityKey'])) {
                $this->setSecurityKey($parts['SecurityKey']);
            }
        }

        return $this;
    }
485501
public function addReference($ruleKey, $columns, $refTableClass, $refColumns,
                                 $onDelete = null, $onUpdate = null)
    {
        $reference = array(self::COLUMNS         => (array) $columns,
                           self::REF_TABLE_CLASS => $refTableClass,
                           self::REF_COLUMNS     => (array) $refColumns);

        if (!empty($onDelete)) {
            $reference[self::ON_DELETE] = $onDelete;
        }

        if (!empty($onUpdate)) {
            $reference[self::ON_UPDATE] = $onUpdate;
        }

        $this->_referenceMap[$ruleKey] = $reference;

        return $this;
    }
569485
public function dropForeignKey($referenceTable, $referenceColumns, array $options = [])
    {
        $schema = isset($options['schema']) ? new Schema($options['schema']) : null;

        $foreignKey = new ForeignKey($this, new Table($referenceTable, $schema));
        $foreignKey->setColumns($referenceColumns);
        $foreignKey->setReferencedColumns($referenceColumns);

        $this->actions[] =  function () use ($foreignKey) {
             return $this->manipulation->drop($foreignKey);
        };

        return $this;
    }
236150
public function hasMany(string $related, string $primary_key = '', string $foreign_key = '')
    {
        $relatedModel = app()->make($related);
        $local_key = $local_key ?? $this->getKey();
        // Make the table name singular and append ID to it
        // FIXME: Use a more reliable approach
        $foreign_key = $foreign_key ?? rtrim($relatedModel->getTable(), 's').'_id';
        return new HasMany($relatedModel, $this, $primary_key, $foreign_key);
    }
863251
function via( $key ) {

        if ( !$this->parent_ ) throw new \LogicException( 'Cannot set reference key on basic Result' );

        $clone = clone $this;

        if ( $clone->single ) {

            $clone->parentKey = $key;

        } else {

            $clone->key = $key;

        }

        return $clone;

    }
427581
protected function getForeignKeyReferenceCount($fkey, $max = null)
    {
        $count = 0;
        $tablename = $fkey->getReferencedTable()->getRawTableName();
        $columns = array();
        foreach ($this->getColumns() as $column) {
            foreach ($column->getForeignKeys() as $foreignKey) {
                // process only unique foreign key
                if (in_array($foreignKey->getId(), $columns)) {
                    continue;
                }
                $columns[] = $foreignKey->getId();
                if ($this->checkForeignKeyOwnerTableName($foreignKey, $tablename)) {
                    $count++;
                }
                if ($max && $count == $max) {
                    break;
                }
            }
        }

        return $count;
    }
253610
public function fixIdentities($unique = null) {
        if ($this->children) {
            if (!isset($unique))
                $unique = array_unique($this->flat());

            foreach ($this->children as $i => $child) {
                if (!$child instanceof BranchPattern) {
                    if (!in_array($child, $unique))               // Not sure if this is a true substitute for 'assert c in uniq'
                        throw new \UnexpectedValueException();
                    $this->children[$i] = $unique[array_search($child, $unique)];
                }
                else {
                    $child->fixIdentities($unique);
                }
            }
        }
        return $this;
    }
583848
public function setReferenceId($referenceId)
    {
        $this->referenceId = $referenceId;
        $this->email = null;
        $this->executed = false;
        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;
    }
825560
public function reverse($preserveKeys = false) : self
    {
        $clone = clone $this;
        $clone->elements = array_reverse($this->elements, $preserveKeys);

        return $clone;
    }
411857
public function addUniqueKey($name, array $fields)
    {
        //Argument 1 must be a string
        Argument::i()->test(1, 'string');
        
        $this->uniqueKeys[$name] = $fields;
        return $this;
    }
1001676
public function addIndex(array $columns, bool $unique = false, string $prefix = null): Table
    {
        $this->indexes[] = new Index($columns, $unique, $prefix);

        return $this;
    }
117898
protected function pushAttributes(&$subject, array $attributes, bool $unique = true)
    {
        foreach ($attributes as $attribute) {
            if ($unique === false || in_array($attribute, $subject) === false) {
                $subject[] = $attribute;
            }
        }
        return $this;
    }
519548
protected function pushKeys( $namespace, $key, $reference )
	{
		$fullKey = $this->getPrefix() . sha1( $namespace ) . ':' . $key;

		foreach ( explode( '|', $namespace ) as $segment )
		{
			$this->store->connection()->sadd( $this->referenceKey( $segment, $reference ), $fullKey );
		}
	}