From cd7d74d9a1bdd8f3ba4c97160b667b91fef8fb28 Mon Sep 17 00:00:00 2001 From: liviuk2 Date: Mon, 16 Oct 2023 11:03:28 +0200 Subject: [PATCH 1/2] UserSearch avoid fields name conflict if joined with other tables --- src/User/Search/UserSearch.php | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/User/Search/UserSearch.php b/src/User/Search/UserSearch.php index ae462d9a..b9367660 100644 --- a/src/User/Search/UserSearch.php +++ b/src/User/Search/UserSearch.php @@ -11,7 +11,9 @@ namespace Da\User\Search; +use Da\User\Model\User; use Da\User\Query\UserQuery; +use Da\User\Traits\ContainerAwareTrait; use Yii; use yii\base\InvalidParamException; use yii\base\Model; @@ -19,6 +21,8 @@ class UserSearch extends Model { + use ContainerAwareTrait; + /** * @var string */ @@ -106,21 +110,23 @@ public function search($params) return $dataProvider; } + $userClass = $this->getClassMap()->get(User::class); + if ($this->created_at !== null) { $date = strtotime($this->created_at); - $query->andFilterWhere(['between', 'created_at', $date, $date + 3600 * 24]); + $query->andFilterWhere(['between', $userClass::tableName().'.created_at', $date, $date + 3600 * 24]); } if ($this->last_login_at !== null) { $date = strtotime($this->last_login_at); - $query->andFilterWhere(['between', 'last_login_at', $date, $date + 3600 * 24]); + $query->andFilterWhere(['between', $userClass::tableName().'.last_login_at', $date, $date + 3600 * 24]); } $query - ->andFilterWhere(['like', 'username', $this->username]) - ->andFilterWhere(['like', 'email', $this->email]) - ->andFilterWhere(['registration_ip' => $this->registration_ip]) - ->andFilterWhere(['last_login_ip' => $this->last_login_ip]); + ->andFilterWhere(['like', $userClass::tableName().'.username', $this->username]) + ->andFilterWhere(['like', $userClass::tableName().'.email', $this->email]) + ->andFilterWhere([$userClass::tableName().'.registration_ip' => $this->registration_ip]) + ->andFilterWhere([$userClass::tableName().'.last_login_ip' => $this->last_login_ip]); return $dataProvider; } From 214eef6f16502fa77b36f94efc75b911d2279696 Mon Sep 17 00:00:00 2001 From: liviuk2 Date: Mon, 16 Oct 2023 11:03:57 +0200 Subject: [PATCH 2/2] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5716b649..79d39d9c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ - Fix: update Dutch (nl) translations (squio) - Enh: possibility to limit the depth of the recursion when getting user ids from roles (mp1509) +- Fix: UserSearch avoid fields name conflict if joined with other tables (liviuk2) ## 1.6.1 March 4th, 2023