getId()) { $otherEntityWithThisKey = $this->findByKey($entity->getKey()); if ($otherEntityWithThisKey) $entity->setId($otherEntityWithThisKey->getId()); } parent::save($entity); } public function findByKey($key) { return $this->findOneBy('key', $key); } public function deleteByKey($key) { return $this->deleteBy('key', $key); } }