php - Symfony - EasyAdmin - 从 AssociationField 中忽略添加和删除功能
问题描述
我使用了最新版本的 EasyAdmin,提交表单时忽略了我的add
和remove
函数:
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
但是当我添加车辆并提交我的表单时,没有插入任何数据。
解决方案
我正在努力解决同样的问题,但我已经发现了一些可能有用的难题:
- 以我的经验,似乎关联的拥有方(在数据库中具有外键的一方)会生成一个保留更改的编辑表单。
- 对方完全无视变化
- 由于我也不清楚的原因,setter 和 getter 以及 addABC 和 removeABC 方法似乎确实被跳过了。
我希望你能找到一个解决方案,暗示关系中的 crudcontroller 另一方,我认为你的情况是车辆。
推荐阅读
- cmd - Windows 控制台:从大文件中提取特定范围的行到新文件
- python - 将html读入pandas时'没有匹配模式'.+'的表
- class - 如何按每个 id 映射列表中的最新记录?
- c++ - 为什么 a[21] 不等于 a[021]?
- java - 如何配置 Gradle 缓存的自动清理?- 排除一些目录?
- unity3d - unity 雾裁剪
- javascript - 我想制作一个“剧透警报”按钮
- flutter - 如何使用 Flutter 创建这样的 UI?请帮我
- python - 如何使用 yum 在 EC2 实例中将 python version3.8 降级到 3.7
- java - 无法在 spark 上读取外部配置单元表