Skip to content

Commit 77b07f5

Browse files
committed
fix: possibilité de desactivé le hash des alias par defaut de table
1 parent a35cbd0 commit 77b07f5

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

src/Connection/BaseConnection.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,11 @@ abstract class BaseConnection implements ConnectionInterface
262262
*/
263263
protected array $aliasedTables = [];
264264

265+
/**
266+
* Specifie si on ajoute un hash a l'alias de table lorsqu'aucun alias n'est defini
267+
*/
268+
public static bool $useHashedAliases = true;
269+
265270
/**
266271
* Query Class
267272
*/
@@ -550,6 +555,10 @@ public function makeTableName(string $table): string
550555

551556
[$alias, $table] = $this->getTableAlias($table);
552557

558+
if ($alias === $table) {
559+
return $this->prefixTable($table);
560+
}
561+
553562
return $this->prefixTable($table) . ' As ' . $this->escapeIdentifiers($alias);
554563
}
555564

@@ -571,7 +580,7 @@ public function getTableAlias(string $table): array
571580
$alias = trim($matches[1]);
572581
$table = str_replace($matches[0], '', $table);
573582
} else {
574-
$alias = $table . '_' . uniqid();
583+
$alias = $table . (static::$useHashedAliases ? '_' . uniqid() : '');
575584
}
576585
} else {
577586
$key = array_search($table, $this->aliasedTables, true);
@@ -580,7 +589,7 @@ public function getTableAlias(string $table): array
580589
$alias = $this->aliasedTables[$key];
581590
$table = $key;
582591
} else {
583-
$alias = $table . '_' . uniqid();
592+
$alias = $table . (static::$useHashedAliases ? '_' . uniqid() : '');
584593
}
585594
}
586595

@@ -593,7 +602,7 @@ public function getTableAlias(string $table): array
593602
}
594603
}
595604

596-
return [$this->aliasedTables[$table], $table];
605+
return [$this->aliasedTables[$table] ?? $table, $table];
597606
}
598607

599608
/**

0 commit comments

Comments
 (0)