我在Symfony 6中创建了一个Artist实体和一个User实体。这两个实体都具有ManyToMany关系,因此创建了一个连接表。
用户实体
#[ORM\OneToMany(mappedBy: 'author', targetEntity: Comment::class)]
private $comments;
#[ORM\ManyToMany(targetEntity: Artist::class, inversedBy: 'users')]
private $artists;
public function __construct()
{
$this->comments = new ArrayCollection();
$this->artists = new ArrayCollection();
}
艺术家实体
#[ORM\ManyToMany(targetEntity: User::class, mappedBy: 'artists')]
private $users;
public function __construct()
{
$this->albums = new ArrayCollection();
$this->concerts = new ArrayCollection();
$this->users = new ArrayCollection();
}
在EasyAdmin中,在ArtistCrudController中,我想关联两个表。但是它们没有外键。外键在连接表(user_artist)中,所以AssociationField不能工作。我如何在CrudController中关联两个实体?
1条答案
按热度按时间nhn9ugyo1#
在多对多关系中应使用CollectionType而不是AssociationType
https://symfony.com/bundles/EasyAdminBundle/current/fields/CollectionField.html