It is not clear what the $alergenosUsuarioIds
and $alergen
variables represent but you might be mistaken about the usage of the remove()
method of ArrayCollection
.
You need to give it an index, not the id of the entity you want to remove. You can also use the removeElement()
method and pass it the entity.
For instance you can do something like this :
$elements = $alergenosUser->getAlergenos();
foreach ($elements as $element) {
if ($element->getId() == $id_from_array_diff_or_whatever) {
$elements->removeElement($element);
}
}
or
$elements = $alergenosUser->getAlergenos();
foreach ($elements as $key => $element) {
if ($element->getId() == $id_from_array_diff_or_whatever) {
$elements->remove($key);
// or
unset($elements[$key]);
}
}
You can also use the matching()
but I'm not sure it's available with the version shipped with symfony2 2.1.