doctrine2 - Doctrine swap out table at runtime -
typically when implement entity using doctrine map table explicitly: <?php /** * @entity * @table(name="message") */ class message { //... } or reply on doctrine implicitly map class name table...i have several tables identical in schema not wish re-create class each time...there fore @ runtime (dynamically) change table name accordingly. where start or overriding implement odd requirement??? surprisingly (to me), solution simple. have classmetadata of entity , change name of table maps to: /** @var entitymanager $em */ $class = $em->getclassmetadata('message'); $class->setprimarytable(['name' => 'message_23']); you need careful , not change table name after have loaded entities of type message , changed them. it's big chance either produce sql errors on saving (because of table constraints, example), if lucky or modify wrong row (from new table). i suggest following workflow: set desired table name;...