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;