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)
This commit is contained in:
Romain 'Maz' BILLOIR 2020-04-01 00:45:19 +02:00 committed by GitHub
parent 6e25c5a8d0
commit 2b22c0e49a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 4 deletions

View File

@ -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;