Hello, do you know if there is a way to detach an entity on the many to
many bidirectional relationship?
I'm having some problems, specific:
Warning: array_pop() expects parameter 1 to be array, null given in
/my/path/to
/vendor/doctrine/orm/lib/Doctrine/ORM/Persisters/Collection/ManyToManyPersister.php
on
line 532
The context of the warning is:
- I have a person Entity and an Address entity with a many to many
relationship between them;
- The person entity is used with a doctrine hydrator to populate my form
with person and addresses data for a specific person.
- If the person changes an address and send the form I will have the
cases:
- Case 1: The address already exists on database. So I remove the
previous address from person ($person->removeAddress($address)), detach
the
previous address ($em->detach($address)) and add the new one from
database
($person->addAddress($addressFormDatabase));
- Case 2: The address does not exists on database. I remove the
previous address, detach it, create a new one and add to person;
The problem is that the previous address is not removed from person
(produces the warning) but the new one is saved and associated correctly.
my addAddress and removeAddress code is
/**
* @param Address $address
* @return Person
*/
public function removeAddress(Address $address)
{
$address->removePerson($this);
$this->addresses->removeElement($address);
return $this;
}
/**
* @param Address $address
* @return Person
*/
public function addAddress(Address $address)
{
if (!$this->hasAddress($address)) {
$address->addPerson($this);
$this->addresses->add($address);
}
return $this;
}
--
You received this message because you are subscribed to the Google Groups
"doctrine-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/doctrine-user.
For more options, visit https://groups.google.com/d/optout.