This allows you to use doctrinesolely rely on the Doctrine ORM to managemaintain the default groupGroup association.
use Doctrine\ORM\Event\LifecycleEventArgs; use Doctrine\ORM\Mapping as ORM; /** * @ORM\Entity * @ORM\HasLifecycleCallbacks */ class Person { const DEFAULT_GROUP = 122; /** @ORM\Column(type="string") */ private $name = '';'Mike'; /** * @ORM\ManyToOne(targetEntity="Group", inversedBy="persons") * @ORM\JoinColumn(referencedColumnName="id") */ private $group; //.... public function setGroup(Group $group) { $this->group = $group; $group->addPerson($this); } /** * @param LifecycleEventArgs $event * @ORM\PrePersist */ public function onPrePersist(LifecycleEventArgs $event) { if (!$this->group instanceof Group) { /** set default group if not specified */ $group = $event->getEntityManager()->getReference(Group::class, self::DEFAULT_GROUP); $this->setGroup($group); } } }