diff --git a/src/Form.php b/src/Form.php index d172a43a36..cdc3386aae 100644 --- a/src/Form.php +++ b/src/Form.php @@ -368,7 +368,7 @@ public function controlFactory(Field $field, $controlSeed = []): Control if ($field->type === 'json' && $field->hasReference()) { $limit = ($field->getReference() instanceof ContainsMany) ? 0 : 1; - $model = $field->getReference()->refModel($this->model); + $model = $field->getReference()->createTheirModel(); $fallbackSeed = [Control\Multiline::class, 'model' => $model, 'rowLimit' => $limit, 'caption' => $model->getModelCaption()]; } elseif ($field->type !== 'boolean') { if ($field->enum !== null) { @@ -376,7 +376,7 @@ public function controlFactory(Field $field, $controlSeed = []): Control } elseif ($field->values !== null) { $fallbackSeed = [Control\Dropdown::class, 'values' => $field->values]; } elseif ($field->hasReference()) { - $fallbackSeed = [Control\Lookup::class, 'model' => $field->getReference()->refModel($this->model)]; + $fallbackSeed = [Control\Lookup::class, 'model' => $field->getReference()->createTheirModel()]; } } diff --git a/src/Form/Control/Multiline.php b/src/Form/Control/Multiline.php index 5aa1cff0be..57a332e49f 100644 --- a/src/Form/Control/Multiline.php +++ b/src/Form/Control/Multiline.php @@ -557,7 +557,7 @@ protected function getLookupProps(Field $field): array public function setLookupOptionValue(Field $field, string $value): void { - $model = $field->getReference()->refModel($this->model); + $model = $field->getReference()->createTheirModel(); $entity = $model->tryLoadBy($field->getReference()->getTheirFieldName($model), $this->getApp()->uiPersistence->typecastLoadField($field, $value)); if ($entity !== null) { $option = ['key' => $value, 'text' => $entity->get($model->titleField), 'value' => $value]; @@ -614,7 +614,7 @@ protected function getFieldItems(Field $field, ?int $limit = 10): array if ($field->values !== null) { $items = array_slice($field->values, 0, $limit, true); } elseif ($field->hasReference()) { - $model = $field->getReference()->refModel($this->model); + $model = $field->getReference()->createTheirModel(); $model->setLimit($limit); $theirFieldName = $field->getReference()->getTheirFieldName($model); diff --git a/src/Form/Control/ScopeBuilder.php b/src/Form/Control/ScopeBuilder.php index 33bab27b14..8ffcedd7a7 100644 --- a/src/Form/Control/ScopeBuilder.php +++ b/src/Form/Control/ScopeBuilder.php @@ -458,7 +458,7 @@ protected function getFieldItems(Field $field, ?int $limit = 250): array if ($field->values !== null) { $items = array_slice($field->values, 0, $limit, true); } elseif ($field->hasReference()) { - $model = $field->getReference()->refModel($this->model); + $model = $field->getReference()->createTheirModel(); $model->setLimit($limit); foreach ($model as $item) { @@ -689,7 +689,7 @@ protected function getConditionOption(string $type, $value, Condition $condition case 'lookup': $condField = $condition->getModel()->getField($condition->field); $reference = $condField->getReference(); - $model = $reference->refModel($condField->getOwner()); + $model = $reference->createTheirModel(); $fieldName = $reference->getTheirFieldName($model); $entity = $model->tryLoadBy($fieldName, $value); if ($entity !== null) {