Created
September 13, 2016 22:20
-
-
Save CarlosEduardo/1bb4ed34ce217199c68728cf2d954e40 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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