【问题标题】:Symfony - EasyAdmin - Add and remove functions are ignored from AssociationFieldSymfony - EasyAdmin - 从 AssociationField 中忽略添加和删除功能
【发布时间】:2021-05-05 17:00:27
【问题描述】:

我使用的是最新版本的 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;
}

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

AmbianceCrudController.php 中的我的 EasyAdmin 表单:

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

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

【问题讨论】:

  • 我也有同样的问题。

标签: php symfony doctrine-orm easyadmin easyadmin3


【解决方案1】:

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

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

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

【讨论】:

    猜你喜欢
    • 2021-09-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-07
    相关资源
    最近更新 更多