https://github.com/symfony/symfony/issues/1540
by_reference = false, to call addElement(), removeElement()
$builder->addEventListener(FormEvents::POST_BIND, function(DataEvent $event) use ($em) {
// Inverse relationship that we have to update
$inverse = $event->getData();
// All possible owning-side Entities (very expensive this way, totally a hack)
$owners = $em->getRepository('MyBundle:OwnerEntity')->findAll();
// User-selected collection of owning-side Entities
$owned = $inverse->getOwners();
// Iterate through all possible owners & remove the inverse Entity in question
foreach ($owners as $owner) {
$owner->getInverses()->removeElement($inverse);
$em->persist($owner);
}
// Re-establish the inverse Entity relationship that was just previously removed
foreach ($owned as $owner) {
$owner->getInverses()->add($inverse);
}
// Yes yes, the two previous for-each loops could be done in a single pass, but I'm just typing crap up!
});