Add the match clause for a relationship

@param MapInterface<string, mixed> $changeset
359099
private function matchRelationship(
        Identity $identity,
        object $entity,
        Relationship $meta,
        MapInterface $changeset,
        Query $query
    ): Query {
        $name = $this->name->sprintf(\md5($identity->value()));
        $this->variables = $this->variables->put(
            $name,
            $this->buildProperties(
                $changeset,
                $meta->properties()
            )
        );

        return $query
            ->match()
            ->linkedTo()
            ->through(
                (string) $meta->type(),
                (string) $name
            )
            ->withProperty(
                $meta->identity()->property(),
                (string) $name
                    ->prepend('{')
                    ->append('_identity}')
            )
            ->withParameter(
                (string) $name->append('_identity'),
                $identity->value()
            );
    }
132020
public static function setUnitOfWorkEntityChangeSet($entity, $changeSet, $unitOfWork)
    {
        $reflectionClass = new ReflectionClass(UnitOfWork::class);

        $reflectionProperty = $reflectionClass->getProperty('entityChangeSets');
        $reflectionProperty->setAccessible(true);

        $changeSetFull = $reflectionProperty->getValue($unitOfWork);
        $changeSetFull[$oid = spl_object_hash($entity)] = $changeSet;

        $reflectionProperty->setValue($unitOfWork, $changeSetFull);
    }
803461
protected function recursivelyApplyChanges($changes, $source, &$destination)
    {
        $source = $source ?: [];
        foreach ($changes as $key => $changed) {
            if ($changed === true) {
                // Determine if replacement or removal
                if (array_key_exists($key, $source)) {
                    $destination[$key] = $source[$key];
                } else {
                    unset($destination[$key]);
                }
            } else {
                // Recursively apply
                $destVal = &$this->nestedValueRef($key, $destination);
                $sourceVal = $this->nestedValue($key, $source);
                $this->recursivelyApplyChanges($changed, $sourceVal, $destVal);
            }
        }
    }
677655
private function updateOldAceProperty($name, array $changes)
    {
        list($old, $new) = $changes;
        $currentIds = array();

        for ($i = 0, $c = count($new); $i < $c; ++$i) {
            $ace = $new[$i];

            if (null !== $ace->getId()) {
                $currentIds[$ace->getId()] = true;
            }
        }

        for ($i = 0, $c = count($old); $i < $c; ++$i) {
            $ace = $old[$i];

            if (!isset($currentIds[$ace->getId()])) {
                $this->connection->executeQuery($this->getDeleteAccessControlEntrySql($ace->getId()));
                unset($this->loadedAces[$ace->getId()]);
            }
        }
    }
1314921
public function merge(ObjectSet $set)
    {
        foreach ($set as $object) {
            $this->insert($object);
        }

        return $this;
    }
546537
private static boolean anyArgumentsMatch(
      List<ParameterPair> changedPairs, List<Parameter> arguments) {
    return changedPairs.stream()
        .anyMatch(
            change ->
                Objects.equals(
                    change.actual().text(), arguments.get(change.formal().index()).text()));
  }
1360245
private function update(
        Str $variable,
        MapInterface $changeset,
        Query $query
    ): Query {
        return $query
            ->set(sprintf(
                '%s += {%s_props}',
                $variable,
                $variable
            ))
            ->withParameter(
                (string) $variable->append('_props'),
                $changeset->reduce(
                    [],
                    static function(array $carry, string $key, $value): array {
                        $carry[$key] = $value;

                        return $carry;
                    }
                )
            );
    }
1046276
public function applyChanges(array $changes): void
    {
        /* @var $change TableChange */
        foreach ($changes as $change) {
            if (!$change instanceof TableChange) {
                throw new InvalidArgumentException('You must provide array of TableChange objects.');
            }

            switch ($change->method) {
                case 'createTable':
                    /* @var $column TableColumn */
                    foreach ($change->value as $column) {
                        $this->columns[$column->name] = $column;

                        if ($column->isPrimaryKey || $column->isColumnAppendPK()) {
                            if ($this->primaryKey === null) {
                                $this->primaryKey = new TablePrimaryKey(['columns' => [$column->name]]);
                            } else {
                                $this->primaryKey->addColumn($column->name);
                            }
                        }
                    }
                    break;

                case 'addColumn':
                    $this->columns[$change->value->name] = $change->value;

                    if ($change->value->isPrimaryKey || $change->value->isColumnAppendPK()) {
                        if ($this->primaryKey === null) {
                            $this->primaryKey = new TablePrimaryKey(['columns' => [$change->value->name]]);
                        } else {
                            $this->primaryKey->addColumn($change->value->name);
                        }
                    }
                    break;

                case 'dropColumn':
                    unset($this->columns[$change->value]);
                    break;

                case 'renameColumn':
                    if (isset($this->columns[$change->value['old']])) {
                        $this->columns[$change->value['new']] = $this->columns[$change->value['old']];
                        $this->columns[$change->value['new']]->name = $change->value['new'];

                        unset($this->columns[$change->value['old']]);
                    }
                    break;

                case 'alterColumn':
                    $this->columns[$change->value->name] = $change->value;
                    break;

                case 'addPrimaryKey':
                    $this->primaryKey = $change->value;

                    foreach ($this->primaryKey->columns as $column) {
                        if (isset($this->columns[$column])) {
                            if (empty($this->columns[$column]->append)) {
                                $this->columns[$column]->append = $this->columns[$column]->prepareSchemaAppend(true, false);
                            } elseif (!$this->columns[$column]->isColumnAppendPK()) {
                                $this->columns[$column]->append .= ' ' . $this->columns[$column]->prepareSchemaAppend(true, false);
                            }
                        }
                    }
                    break;

                case 'dropPrimaryKey':
                    if ($this->primaryKey !== null) {
                        foreach ($this->primaryKey->columns as $column) {
                            if (isset($this->columns[$column]) && !empty($this->columns[$column]->append)) {
                                $this->columns[$column]->append = $this->columns[$column]->removePKAppend();
                            }
                        }
                    }

                    $this->primaryKey = null;
                    break;

                case 'addForeignKey':
                    $this->foreignKeys[$change->value->name] = $change->value;
                    break;

                case 'dropForeignKey':
                    unset($this->foreignKeys[$change->value]);
                    break;

                case 'createIndex':
                    $this->indexes[$change->value->name] = $change->value;
                    if (
                        $change->value->unique
                        && isset($this->columns[$change->value->columns[0]])
                        && count($change->value->columns) === 1
                    ) {
                        $this->columns[$change->value->columns[0]]->isUnique = true;
                    }
                    break;

                case 'dropIndex':
                    if (
                        $this->indexes[$change->value]->unique
                        && count($this->indexes[$change->value]->columns) === 1
                        && isset($this->columns[$this->indexes[$change->value]->columns[0]])
                        && $this->columns[$this->indexes[$change->value]->columns[0]]->isUnique
                    ) {
                        $this->columns[$this->indexes[$change->value]->columns[0]]->isUnique = false;
                    }
                    unset($this->indexes[$change->value]);
                    break;

                case 'addCommentOnColumn':
                    if (isset($this->columns[$change->value->name])) {
                        $this->columns[$change->value->name]->comment = $change->value->comment;
                    }
                    break;

                case 'dropCommentFromColumn':
                    if (isset($this->columns[$change->value])) {
                        $this->columns[$change->value]->comment = null;
                    }
            }
        }
    }
933928
public function setField(
        string $name,
        $value,
        bool $filter = true,
        bool $registerChanges = true
    ) {
        if ($this->relations->has($name)) {
            //Would not work with relations which do not represent singular entities
            $this->relations->setRelated($name, $value);

            return;
        }

        $this->assertField($name);
        if ($registerChanges) {
            $this->registerChange($name);
        }

        parent::setField($name, $value, $filter);
    }
1023997
private function applyJoinsAndFilters(ClassMetadata $metadata, string $alias, InputObjectType $typeFields, array $joins, array $conditions): void
    {
        $this->applyJoins($metadata, $joins, $alias);
        $this->collectDqlConditions($metadata, $conditions, $typeFields, $alias);
    }
241538
public function addObject(DataObject $object)
    {
        if (!$this->isInDB()) {
            throw new BadMethodCallException("ChangeSet must be saved before adding items");
        }

        if (!$object->isInDB()) {
            throw new BadMethodCallException("Items must be saved before adding to a changeset");
        }

        $references = [
            'ObjectID' => $object->ID,
            'ObjectClass' => $object->baseClass(),
        ];

        // Get existing item in case already added
        $item = $this->Changes()->filter($references)->first();

        if (!$item) {
            $item = new ChangeSetItem($references);
            $this->Changes()->add($item);
        }

        $item->ReferencedBy()->removeAll();

        $item->Added = ChangeSetItem::EXPLICITLY;
        $item->write();

        $this->sync();
    }
1179316
protected function proceedChangeSetsNeededByRelation()
    {
        $dbHandle = $this->getDatabase()->getDatabaseConnection();

        $tmpTable = Database::TABLE_TMP_DEPENDS_NEEDED;
        $neededByTable = Database::TABLE_CHANGESET_NEEDEDBY;
        $changeSetTable = Database::TABLE_CHANGESET;
        $patchSetTable = Database::TABLE_PATCHSET;

        $query = '
            INSERT INTO ' . $neededByTable . ' (`changeset`, `needed_by`, `tstamp`, `crdate`)
            SELECT
                ' . $changeSetTable . '.`id`,
                neededByChangeset.`id`,
                UNIX_TIMESTAMP(),
                UNIX_TIMESTAMP()
            FROM
                ' . $tmpTable . '
                INNER JOIN ' . $changeSetTable . ' AS neededByChangeset ON (
                    ' . $tmpTable . '.`identifier` = neededByChangeset.`identifier`
                    AND ' . $tmpTable . '.`number` = neededByChangeset.`number`
                )
                INNER JOIN gerrit_patchset ON (
                    neededByChangeset.`id` = ' . $patchSetTable . '.`changeset`
                    AND ' . $patchSetTable . '.`revision` = ' . $tmpTable . '.`revision`
                    AND ' . $patchSetTable . '.`ref` = ' . $tmpTable . '.`ref`
                )
                INNER JOIN ' . $changeSetTable . ' ON (
                    ' . $changeSetTable . '.`id` = ' . $tmpTable . '.`changeset`
                )
            WHERE
                ' . $tmpTable . '.`status` = ' . intval(Database::TMP_DEPENDS_NEEDED_STATUS_NEEDEDBY) . '
            GROUP BY
                ' . $changeSetTable . '.`id`, neededByChangeset.`id`
            ON DUPLICATE KEY UPDATE
                ' . $neededByTable . '.`tstamp` = UNIX_TIMESTAMP()';

        $dbHandle->exec($query);
    }
268089
public function setChanges($changes)
    {
        if ($changes instanceof RecordFields) {
            $this->changes = $changes;
        } elseif (is_array($changes)) {
            $recordFields = new RecordFields();
            foreach ($changes as $change) {
                $recordFields->add($change);
            }
            $this->changes = $recordFields;
        }
        return $this;
    }
726603
public function match(array $models, Collection $results, $relation)
    {
        return $this->matchMany($models, $results, $relation);
    }
93948
private function mapDocuments(ResultSet $resultSet)
    {
        $mesages = [];

        foreach ($resultSet->getResults() as $result) {
            $mesages[] = $this->mapDocument($result->getSource());
        }

        return $mesages;
    }
204848
public function relabeledClone($changeMap = [])
    {
        $newParentAlias = ArrayHelper::getValue($changeMap, $this->parentAlias, $this->parentAlias);
        $tableAlias = ArrayHelper::getValue($changeMap, $this->tableAlias, $this->tableAlias);
        $join = new static();
        $join->setTableName($this->getTableName());
        $join->setParentAlias($newParentAlias);
        $join->setTableAlias($tableAlias);
        $join->setJoinType($this->getJoinType());
        $join->setJoinField($this->getJoinField());
        $join->setNullable($this->getNullable());

        return $join;
    }
846520
def _add_match(self, match_key, match_value):
        """"""
        if match_key is None:
            raise errors.NullArgument()
        self._query_terms[match_key] = str(match_key) + '=' + str(match_value)