如何在EasyAdmin 4中使用具有ManyToMany关系的AssociationField



我在Symfony 6中创建了一个艺术家实体和一个用户实体。这两个实体都具有ManyToMany关系,因此创建了一个联接表。

用户实体

#[ORMOneToMany(mappedBy: 'author', targetEntity: Comment::class)]
private $comments;
#[ORMManyToMany(targetEntity: Artist::class, inversedBy: 'users')]
private $artists;
public function __construct()
{
$this->comments = new ArrayCollection();
$this->artists = new ArrayCollection();
}

艺术家实体

#[ORMManyToMany(targetEntity: User::class, mappedBy: 'artists')]
private $users;
public function __construct()
{
$this->albums = new ArrayCollection();
$this->concerts = new ArrayCollection();
$this->users = new ArrayCollection();
}

在EasyAdmin中,在ArtistRudController中,我想关联这两个表。但是他们没有外国钥匙。外键在联接表(user_artist(中,因此AssociationField无法工作。如何将CrudController中的两个实体关联起来?

在ManyToMany关系中应该使用CollectionType而不是AssociationType

https://symfony.com/bundles/EasyAdminBundle/current/fields/CollectionField.html

最新更新