getLocalColumns example



    private function getForeignKey(Connection $connection, string $relationTable): ?ForeignKeyConstraint
    {
        $foreignKeys = $connection->createSchemaManager()->listTableForeignKeys($relationTable);

        foreach ($foreignKeys as $foreignKey) {
            if (!$foreignKey instanceof ForeignKeyConstraint) {
                continue;
            }

            if ($foreignKey->getForeignTableName() === 'salutation' && $foreignKey->getLocalColumns() === ['salutation_id']) {
                return $foreignKey;
            }
        }

        return null;
    }
}

    private function validateForeignKeyOnDeleteBehaviour(EntityDefinition $definition, OneToManyAssociationField|ManyToManyAssociationField $association, EntityDefinition $reference, array $associationViolations): array
    {
        $manager = $this->connection->createSchemaManager();

        if ($association->getFlag(CascadeDelete::class)
            || $association->getFlag(RestrictDelete::class)
            || $association->getFlag(SetNullOnDelete::class)) {
            $fks = $manager->listTableForeignKeys($reference->getEntityName());

            foreach ($fks as $fk) {
                if ($fk->getForeignTableName() !== $definition->getEntityName() || !\in_array($association->getReferenceField()$fk->getLocalColumns(), true)) {
                    continue;
                }

                $deleteFlag = $association->getFlag(CascadeDelete::class)
                    ?? $association->getFlag(RestrictDelete::class)
                    ?? $association->getFlag(SetNullOnDelete::class);

                if (!$deleteFlag instanceof Flag) {
                    continue;
                }

                

    protected function getColumnForeignKey($table$column)
    {
        /** @var \Doctrine\DBAL\Schema\ForeignKeyConstraint $foreignKey */
        foreach ($table->getForeignKeys() as $foreignKey) {
            foreach ($foreignKey->getLocalColumns() as $foreignKeyColumn) {
                if ($foreignKeyColumn === $column->getName()) {
                    return $foreignKey;
                }
            }
        }

        return null;
    }

    /** * Helper function to convert the boolean value of the function "column->getNotNull()" to * a string which can be used for the doctrine annotation. * * @param \Doctrine\DBAL\Schema\Column $column * * @return string */
Home | Imprint | This part of the site doesn't use cookies.