InfyOm\Generator\Utils\TableFieldsGenerator::getPrimaryKeyFromTable PHP Méthode

getPrimaryKeyFromTable() public static méthode

public static getPrimaryKeyFromTable ( string $tableName ) : string | null
$tableName string
Résultat string | null The column name of the (simple) primary key
    public static function getPrimaryKeyFromTable($tableName)
    {
        $schema = DB::getDoctrineSchemaManager();
        $indexes = collect($schema->listTableIndexes($tableName));
        $primaryKey = $indexes->first(function ($i, $index) {
            return $index->isPrimary() && 1 === count($index->getColumns());
        });
        return !empty($primaryKey) ? $primaryKey->getColumns()[0] : null;
    }