From 2b22c0e49a76e271e1ade884f21a365f17f32a24 Mon Sep 17 00:00:00 2001 From: Romain 'Maz' BILLOIR Date: Wed, 1 Apr 2020 00:45:19 +0200 Subject: [PATCH] Allows model scope with join (#4970) More info in [this forum post](https://octobercms.com/forum/post/displays-a-related-model-with-scope-which-uses-join-doesnt-work-is-that-an-october-issue) --- modules/backend/formwidgets/Relation.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/backend/formwidgets/Relation.php b/modules/backend/formwidgets/Relation.php index 6571a67ba..c80be476a 100644 --- a/modules/backend/formwidgets/Relation.php +++ b/modules/backend/formwidgets/Relation.php @@ -127,14 +127,14 @@ class Relation extends FormWidgetBase $query->where($relationModel->getKeyName(), '<>', $model->getKey()); } - if ($scopeMethod = $this->scope) { - $query->$scopeMethod($model); - } - // Even though "no constraints" is applied, belongsToMany constrains the query // by joining its pivot table. Remove all joins from the query. $query->getQuery()->getQuery()->joins = []; + if ($scopeMethod = $this->scope) { + $query->$scopeMethod($model); + } + // Determine if the model uses a tree trait $treeTraits = ['October\Rain\Database\Traits\NestedTree', 'October\Rain\Database\Traits\SimpleTree']; $usesTree = count(array_intersect($treeTraits, class_uses($relationModel))) > 0;