public function addToCollection($object, $value)
{
if (!$this->isCollection()) {
throw new \LogicException(sprintf('The property mapping of this relationship is not of collection type in "%s"', $this->className));
}
/** @var Collection $coll */
$coll = $this->getValue($object);
$toAdd = true;
$oid2 = spl_object_hash($value);
foreach ($coll->toArray() as $el) {
$oid1 = spl_object_hash($el);
if ($oid1 === $oid2) {
$toAdd = false;
}
}
if ($toAdd) {
$coll->add($value);
}
}