Created
August 2, 2012 15:12
-
-
Save marzocchi/3237804 to your computer and use it in GitHub Desktop.
Change a Doctrine entity's table name at runtime
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 | |
class FooController extends Controller { | |
function fooAction() { | |
$em = $this->getDoctrine()->getEntityManager(); | |
$cm = $em->getClassMetadata('FooBundle:FooEntity'); | |
$cm->setTableName('special_table_name'); | |
$repo = $em->getRepository('FooBundle:FooEntity'); | |
$entities = $repo->createQueryBuilder('f') | |
->setMaxResults(1) | |
->orderBy('f.id', 'desc') | |
->getQuery() | |
->getResult(); | |
return new Response(''); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Great!