Embedding one-to-one relations in EasyAdmin / Symfony 5

607 Views Asked by At

I have two entities, Member, MemberGroup and Group. MemberGroup has Group, Member and Role in Group. The relationship between Member and MemberGroup is one-to-one.

I want to embed the MemberGroup relationship in the MemberGroup where you can choose group and role of member in the Group.

I tried Collection field type but that works with collections, association field types give me an auto select field.

How would I achieve this in EasyAdmin3?

I tried to create a custom form type:

\\MemberCRUDController.php

public function configureFields(string $pageName): iterable
    {
        return [
           ....
           AssociationField::new('memberGroup')->setEntryType(GroupMemberType::class)
           ....
];
}

//Form\GroupMemberType.php
namespace App\Form;

use App\Entity\GroupMember;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

class GroupMemberType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('role')
            ->add('community')
        ;
    }

     $resolver->setDefaults([
            'data_class' => GroupMember::class,
        ]);
}

I get an error 'query_builder' and 'class' are unknown.

1

There are 1 best solutions below

3
On

Resolved this by using embedded / embeddable entities