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

3

6

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 !

Agnew answered 7/7, 2020 at 9:32 Comment(3)
would you show your Batiment entity class?Biogeography
Can you show your batiment easy admin config (yaml) ?Oresund
Did you find a way to solve this?Streamlet
A
8

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')
        ];
    }
}
Aquilegia answered 12/8, 2020 at 22:53 Comment(2)
AssociationField::new('...') works for me. thanks ;-)Frangipani
AssociationField::new('products') worked for me to, thank you !Apollonius
A
0

This is the definition of my Batiment entity class

    <?php

namespace App\Entity;

use App\Repository\BatimentRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity(repositoryClass=BatimentRepository::class)
 */
class Batiment
{
    /**
     * @ORM\Id()
     * @ORM\GeneratedValue()
     * @ORM\Column(type="integer")
     */
    private $id;

    /**
     * @ORM\Column(type="string", length=255)
     */
    private $name;

    /**
     * @ORM\Column(type="string", length=255, nullable=true)
     */
    private $Letter;

    /**
     * @ORM\Column(type="string", length=255, nullable=true)
     */
    private $image;

    /**
     * @ORM\OneToMany(targetEntity=Salle::class, mappedBy="batiment")
     */
    private $salles;

    public function __construct()
    {
        $this->salles = new ArrayCollection();
    }

    public function getId(): ?int
    {
        return $this->id;
    }

    public function getName(): ?string
    {
        return $this->name;
    }

    public function setName(string $name): self
    {
        $this->name = $name;

        return $this;
    }

    public function getLetter(): ?string
    {
        return $this->Letter;
    }

    public function setLetter(?string $Letter): self
    {
        $this->Letter = $Letter;

        return $this;
    }

    public function getImage(): ?string
    {
        return $this->image;
    }

    public function setImage(?string $image): self
    {
        $this->image = $image;

        return $this;
    }

    /**
     * @return Collection|Salle[]
     */
    public function getSalles(): Collection
    {
        return $this->salles;
    }

    public function addSalle(Salle $salle): self
    {
        if (!$this->salles->contains($salle)) {
            $this->salles[] = $salle;
            $salle->setBatiment($this);
        }

        return $this;
    }

    public function removeSalle(Salle $salle): self
    {
        if ($this->salles->contains($salle)) {
            $this->salles->removeElement($salle);
            // set the owning side to null (unless already changed)
            if ($salle->getBatiment() === $this) {
                $salle->setBatiment(null);
            }
        }

        return $this;
    }

    public function __toString()
    {
        return $this->name;
    }
}
Agnew answered 7/7, 2020 at 14:30 Comment(0)
A
0

Concerning batiment easy admin config (yaml), I have no particular configuration.

I did not find a point concerning this question in the documentation of easyadmin 3.x.`

Using easyadmin documention 2.x I try to put these parameters in config/packages/easyadmin.yaml.

No success !

easy_admin:
    entities:
#        # List the entity class name you want to manage
        - App\Entity\Batiment
        - App\Entity\DispositionSalle
        - App\Entity\Salle

Agnew answered 7/7, 2020 at 14:35 Comment(1)
There is no more yaml in EasyAdmin 3 : see The Road to EasyAdmin 3: No More YAMLTroupe

© 2022 - 2024 — McMap. All rights reserved.