Skip to content

Instantly share code, notes, and snippets.

@CarlosEduardo
Created September 13, 2016 22:20
Show Gist options
  • Save CarlosEduardo/1bb4ed34ce217199c68728cf2d954e40 to your computer and use it in GitHub Desktop.
Save CarlosEduardo/1bb4ed34ce217199c68728cf2d954e40 to your computer and use it in GitHub Desktop.
<?php
namespace Application;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity
* @ORM\Table(name="documents")
* @ORM\HasLifecycleCallbacks
*/
class Document
{
/**
* @ORM\PrePersist
*/
public function onPrePersistSetParent()
{
$repository = $this->getEntityManager()->getRepository(static::class);
$parent = $repository->findOneBy(['code' => $this->getParentCode()]);
$this->setParent($parent);
}
protected function getEntityManager()
{
return // ... return EntityManager
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment