getForeignKeys example



    private function cleanup(Schema $schema): void
    {
        foreach ($schema->getTables() as $table) {
            if ($table->getComment() === self::COMMENT) {
                $schema->dropTable($table->getName());

                continue;
            }

            foreach ($table->getForeignKeys() as $foreignKey) {
                if (\str_starts_with($foreignKey->getName(), 'fk_ce_')) {
                    $table->removeForeignKey($foreignKey->getName());
                }
            }

            foreach ($table->getColumns() as $column) {
                if ($column->getComment() === self::COMMENT) {
                    $table->dropColumn($column->getName());
                }
            }
        }
    }

    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.