Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony EasyAdmin 3.x ManyToMany error when adding : The Doctrine type of the .... field is "4", which is not supported by EasyAdmin yet

I'm trying to do a simple ManyToMany relation between two classes with easyAdmin 3.x , when I'm trying to show entity CRUD , I have constantly this error:

The Doctrine type of the "salles" field is "4", which is not supported by EasyAdmin yet.

Th function __to string exist for the both entity

public function __toString()
    {
        return $this->name;
    }

My CrudController:

namespace App\Controller\Admin;

use App\Entity\Batiment;
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController;


class BatimentCrudController extends AbstractCrudController
{
    public static function getEntityFqcn(): string
    {
        return Batiment::class;
    }


    public function configureFields(string $pageName): iterable
    {
        return [
            'name',
            'salles'

        ];
    }

}

Does easyadmin 3.x don't manage manytomany relations?

Is there a particular way to manage and display these relations?

I discover this bundle and thank you for your help !

like image 822
jerome linher Avatar asked Jul 07 '20 09:07

jerome linher


1 Answers

In EasyAdmin 3.x a new dedicated type of fied has been added for all association mappings.

Please use something like:

namespace App\Controller\Admin;
    
use App\Entity\Batiment;
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController;
use EasyCorp\Bundle\EasyAdminBundle\Field\AssociationField;
use EasyCorp\Bundle\EasyAdminBundle\Field\Field;
        
        
class BatimentCrudController extends AbstractCrudController
{
    public static function getEntityFqcn(): string
    {
        return Batiment::class;
    }

    public function configureFields(string $pageName): iterable
    {
        return [
            Field::new('id')->hideOnForm(),
            Field::new('name'),
            Field::new('Letter'),
            ImageField::new('image'),
            AssociationField::new('products')
        ];
    }
}
like image 126
Radu Dragomir Avatar answered Nov 15 '22 07:11

Radu Dragomir