Reputation: 367
I'm trying to populate select box with OneToMany relationship in EasyAdmin form. However, the status field is not being populated with the TaskStatus records from my database, while the assignedUsers does. Here's my FormType:
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add(
'assignedUsers',
EntityType::class, [
'class' => User::class,
'label' => 'Choose assigned users',
'multiple' => true,
'required' => true
]
)
->add('status',
EntityType::class, [
'class' => TaskStatus::class,
'label' => 'Task status',
'choice_label' => 'title',
'choice_value' => 'id',
'multiple' => false,
'required' => true
]);
}
Here's my Task and TaskStatus entity relations:
TASK:
/**
* @ORM\ManyToOne(targetEntity="App\Components\Task\Entity\TaskStatus", inversedBy="task")
*/
protected $status;
TASK STATUS:
/**
* @ORM\OneToMany(targetEntity="App\Components\Task\Entity\Task", mappedBy="status")
**/
private $task;
Upvotes: 0
Views: 447
Reputation: 367
The problem was that I used wrong repository for my TaskStatus entity:
/**
* @ORM\Entity(repositoryClass="App\Components\Task\Repository\TaskRepository")
*/
Right one is:
/**
* @ORM\Entity(repositoryClass="App\Components\Task\Repository\TaskStatusRepository")
*/
Upvotes: 1