-
Notifications
You must be signed in to change notification settings - Fork 111
ScopeBuilder with hasOne reference not working #1853
Copy link
Copy link
Closed
Labels
Description
Steps to reproduce:
- Define two models with MySQL persistence, e.g. customer and agent, where contract has a hasOne reference to agent.
- The hasOne reference needs to be set like this:
$this->hasOne('agent_id', ['model' => [Agent::class], 'required' => true])->addTitle(); - Create a view with a form
$formand add a ScopeBuilder to it.
When rendering, I receive this error:

If you set the hasOne reference like this:
$this->hasOne('agent_id', ['model' => [Agent::class], 'theirField' => 'id', 'required' => true])->addTitle();
the exception won't be triggered. I think atk4/data should make sure to continue to automatically assume theirField to be id if it is not set.
Inside getLookupProps when calling getFieldItems and then $items[$item->get($field->getReference()->getTheirFieldName())] = ... , the $this->model is an array and not a model object, so inside getTheirFieldName this call runs an exception: Model::assertInstanceOf($this->model) .
ui/src/Form/Control/ScopeBuilder.php
Line 478 in 32e2742
| $items[$item->get($field->getReference()->getTheirFieldName())] = $item->get($model->titleField); |
Reactions are currently unavailable
