0

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;
5
  • What do you mean with populate? Commented Jun 19, 2020 at 8:22
  • The select box stays empty, I have 3 TaskStatus records in my database. Commented Jun 19, 2020 at 8:23
  • empty in 3 empty lines or empty in no entries? (check in output html) Commented Jun 19, 2020 at 8:42
  • Empty in no entries - <select id="task_status" name="task[status]" class="form-control"></select> Commented Jun 19, 2020 at 8:44
  • that is indeed really weird. have you tried clearing the cache? have you excluded all non-obvious mistakes, like different database is used than the one you're looking at, wrong table looked at. Have you checked in code to retrieve the TaskStatus via EntityManager? maybe form theming that removes the options for that particular field? Commented Jun 19, 2020 at 9:16

1 Answer 1

1

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")
 */
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.