Skip to content

Instantly share code, notes, and snippets.

@rande
Created November 3, 2010 22:24
Show Gist options
  • Save rande/661824 to your computer and use it in GitHub Desktop.
Save rande/661824 to your computer and use it in GitHub Desktop.
custom targetEntity
<?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