首页 > 解决方案 > Symfony - EasyAdmin - 从 AssociationField 中忽略添加和删除功能

问题描述

我使用了最新版本的 EasyAdmin,提交表单时忽略了我的addremove函数:

Ambiance实体:

/**
 * @ORM\OneToMany(targetEntity="Vehicule", mappedBy="ambiance")
 */
protected Collection $vehicules;

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

public function addVehicule(Vehicule $vehicule): self
{
    if (!$this->vehicules->contains($vehicule)) {
        $this->vehicules[] = $vehicule;
        $vehicule->setAmbiance($this);
    }

    return $this;
}

public function removeVehicule(Vehicule $vehicule): void
{
    if (!$this->vehicules->contains($vehicule)) {
        return;
    }

    $this->vehicules->removeElement($vehicule);
}

public function getVehicules()
{
    return $this->vehicules;
}

public function setVehicules($vehicules): void
{
    $this->vehicules = $vehicules;
}

然而我的教义映射是有效的..

我的 EasyAdmin 表格AmbianceCrudController.php

'vehicules' => AssociationField::new('vehicules', 'Véhicules'),

它生成一个multiple select2但是当我添加车辆并提交我的表单时,没有插入任何数据。

标签: phpsymfonydoctrine-ormeasyadmineasyadmin3

解决方案


我正在努力解决同样的问题,但我已经发现了一些可能有用的难题:

  • 以我的经验,似乎关联的拥有方(在数据库中具有外键的一方)会生成一个保留更改的编辑表单。
  • 对方完全无视变化
  • 由于我也不清楚的原因,setter 和 getter 以及 addABC 和 removeABC 方法似乎确实被跳过了。

我希望你能找到一个解决方案,暗示关系中的 crudcontroller 另一方,我认为你的情况是车辆。


推荐阅读