Created
November 3, 2010 22:24
-
-
Save rande/661824 to your computer and use it in GitHub Desktop.
custom targetEntity
This file contains hidden or 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 Sonata\Bundle\BlogBundle; | |
use Symfony\Component\HttpKernel\Bundle\Bundle; | |
use Doctrine\Common\EventSubscriber; | |
class BlogBundle extends Bundle implements EventSubscriber | |
{ | |
public function boot() { | |
$evm = $this->container->getDoctrine_Orm_EntityManagerService()->getEventManager(); | |
$evm->addEventSubscriber($this); | |
} | |
public function getSubscribedEvents() { | |
return array( | |
'loadClassMetadata' | |
); | |
} | |
public function loadClassMetadata($eventArgs) { | |
$metadata = $eventArgs->getClassMetadata(); | |
if($metadata->name == 'Sonata\Bundle\BlogBundle\Entity\Post') | |
{ | |
$metadata->mapManyToOne(array( | |
'fieldName' => 'user', | |
'targetEntity' => $this->container->getParameter('doctrine_user.user_class'), | |
'invertedBy' => 'posts', | |
)); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment