Add/Update/Remove AssociationField
Hello,
I have a entity with AssociationField and when i submitted the form, but nothing changes... the getters and setters are never called.
$usersPrimary = AssociationField::new('usersPrimary');
$usersSecondary = AssociationField::new('usersSecondary');
My entity:
/**
* @ORM\OneToMany(targetEntity=User::class, mappedBy="clientPrimary")
*/
private $usersPrimary;
/**
* @ORM\ManyToMany(targetEntity=User::class, mappedBy="clientsSecondary")
*/
private $usersSecondary;
/**
* @return Collection|User[]
*/
public function getUsersPrimary(): Collection
{
return $this->usersPrimary;
}
public function addUsersPrimary(User $usersPrimary): self
{
if (!$this->usersPrimary->contains($usersPrimary)) {
$this->usersPrimary[] = $usersPrimary;
$usersPrimary->setClientPrimary($this);
}
return $this;
}
public function removeUsersPrimary(User $usersPrimary): self
{
if ($this->usersPrimary->contains($usersPrimary)) {
$this->usersPrimary->removeElement($usersPrimary);
// set the owning side to null (unless already changed)
if ($usersPrimary->getClientPrimary() === $this) {
$usersPrimary->setClientPrimary(null);
}
}
return $this;
}
/**
* @return Collection|User[]
*/
public function getUsersSecondary(): Collection
{
return $this->usersSecondary;
}
public function addUsersSecondary(User $usersSecondary): self
{
if (!$this->usersSecondary->contains($usersSecondary)) {
$this->usersSecondary[] = $usersSecondary;
$usersSecondary->addClientsSecondary($this);
}
return $this;
}
public function removeUsersSecondary(User $usersSecondary): self
{
if ($this->usersSecondary->contains($usersSecondary)) {
$this->usersSecondary->removeElement($usersSecondary);
$usersSecondary->removeClientsSecondary($this);
}
return $this;
}
I have same problem - OneToMany association does not update other side entity (ManyToOne)
I also encounter the problem with version 3.2.2 of EasyAdmin and Symfony 5.2
Same issue : https://github.com/EasyCorp/EasyAdminBundle/issues/4173
same here :(
Same issue for me. I've tested a ManyToMany relation. I can't update my datas from one side, but there is no update from the other one (same methods for my two entities)
Same issue for me.
Thanks to @mauchede, it works.
You need to add ->setFormTypeOption('by_reference', false) on your AssociationField.
Without that, the setter is not called.
Thank you so much @nicosomb .
You need to add ->setFormTypeOption('by_reference', false) on your AssociationField.
@javiereguiluz I think it should be added to docs. Actually I thought that it is something like "not implemented yet" and do changes in my project related to it ("many" side was not so important to me).
If some of you understand Symfony Forms well ... what do you think about the following idea?
Should we set by_reference to false by default in AssociationField when the user hasn't defined the by_reference explicitly?
Thanks!
This issue has been automatically closed as part of our end-of-year repository maintenance. As an open-source project with limited resources, we need to focus our efforts on the most current and impactful issues. If this feature or bug is still relevant to you, please create a new issue. For bugs, include a detailed reproducer, and for features, provide a clear explanation of your request. Thank you for your understanding and for supporting our project!