Skip to content

ScopeBuilder with hasOne reference not working #1853

@mkrecek234

Description

@mkrecek234

Steps to reproduce:

  1. Define two models with MySQL persistence, e.g. customer and agent, where contract has a hasOne reference to agent.
  2. The hasOne reference needs to be set like this: $this->hasOne('agent_id', ['model' => [Agent::class], 'required' => true])->addTitle();
  3. Create a view with a form $form and add a ScopeBuilder to it.

When rendering, I receive this error:
image

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) .

$items[$item->get($field->getReference()->getTheirFieldName())] = $item->get($model->titleField);

Here is the content of $this->model:
image

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions