[CORE][DB] Allow specifying the entites to be retrieved, as when using renaming, tables in join would attempt to be selected
This commit is contained in:
parent
5c3d561a67
commit
3227018963
@ -121,17 +121,19 @@ class DB
|
|||||||
* from table aliases to class names. Replaces '{select}' in
|
* from table aliases to class names. Replaces '{select}' in
|
||||||
* $query with the appropriate select list
|
* $query with the appropriate select list
|
||||||
*/
|
*/
|
||||||
public static function sql(string $query, array $params = [])
|
public static function sql(string $query, array $params = [], ?array $entities = null)
|
||||||
{
|
{
|
||||||
if ($_ENV['APP_ENV'] === 'dev' && str_starts_with($query, 'select *')) {
|
if ($_ENV['APP_ENV'] === 'dev' && str_starts_with($query, 'select *')) {
|
||||||
throw new Exception('Cannot use `select *`, use `select {select}` (see ResultSetMappingBuilder::COLUMN_RENAMING_INCREMENT)');
|
throw new Exception('Cannot use `select *`, use `select {select}` (see ResultSetMappingBuilder::COLUMN_RENAMING_INCREMENT)');
|
||||||
}
|
}
|
||||||
$rsmb = new ResultSetMappingBuilder(self::$em, ResultSetMappingBuilder::COLUMN_RENAMING_INCREMENT);
|
$rsmb = new ResultSetMappingBuilder(self::$em, ResultSetMappingBuilder::COLUMN_RENAMING_INCREMENT);
|
||||||
$matches = [];
|
if (\is_null($entities)) {
|
||||||
preg_match_all(self::$table_entity_pattern, $query, $matches);
|
$matches = [];
|
||||||
$entities = [];
|
preg_match_all(self::$table_entity_pattern, $query, $matches);
|
||||||
foreach (F\zip($matches[1], $matches[2]) as [$table, $alias]) {
|
$entities = [];
|
||||||
$entities[$alias] = self::$table_map[$table];
|
foreach (F\zip($matches[1], $matches[2]) as [$table, $alias]) {
|
||||||
|
$entities[$alias] = self::$table_map[$table];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
foreach ($entities as $alias => $entity) {
|
foreach ($entities as $alias => $entity) {
|
||||||
$rsmb->addRootEntityFromClassMetadata($entity, $alias);
|
$rsmb->addRootEntityFromClassMetadata($entity, $alias);
|
||||||
|
Loading…
Reference in New Issue
Block a user