From a17db2c79ccd66cac6713d68c7cfcc112abf6854 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=91cze=20Bence?= Date: Tue, 2 May 2023 18:04:35 +0200 Subject: [PATCH] use the correct table alias in joins 'on clause' --- src/PersistentData/PersistentDataManager.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/PersistentData/PersistentDataManager.php b/src/PersistentData/PersistentDataManager.php index 5932f06..22c9fee 100644 --- a/src/PersistentData/PersistentDataManager.php +++ b/src/PersistentData/PersistentDataManager.php @@ -150,7 +150,7 @@ class PersistentDataManager implements IPersistentDataManager $columns = array_merge($columns, $this->getRelationColumns($table, $relations, $withRelations)); - $this->leftJoinRelations($select, $table, $relations, $withRelations); + $this->leftJoinRelations($select, $table, $table, $relations, $withRelations); $select->columns($columns); } else { $select->columns($columns); @@ -180,19 +180,19 @@ class PersistentDataManager implements IPersistentDataManager return $columns; } - private function leftJoinRelations(Select $select, string $table, array $relations, array $withRelations): void + private function leftJoinRelations(Select $select, string $table, string $tableAlias, array $relations, array $withRelations): void { foreach ($relations as $relation => $relationType) { $relationTableAlias = $table . '__' . $relation; $relationTable = call_user_func([$relationType, 'getTable']); $select->setTableAliases([$relationTableAlias => $relationTable]); - $select->leftJoin($relationTableAlias, [$relationTableAlias, 'id'], '=', [$table, $relation . '_id']); + $select->leftJoin($relationTableAlias, [$relationTableAlias, 'id'], '=', [$tableAlias, $relation . '_id']); $relationsOfRelation = call_user_func([$relationType, 'getRelations']); if (count($withRelations)) { $relationsOfRelation = array_intersect_key($relationsOfRelation, array_flip($withRelations)); } - $this->leftJoinRelations($select, $relationTable, $relationsOfRelation, $withRelations); + $this->leftJoinRelations($select, $relationTable, $relationTableAlias, $relationsOfRelation, $withRelations); } }