?在代码项目中,有对应的分表业务,但是有请求库中如何查询。给出解决方案
$oEntityManager = $this->getDoctrine()->getManager();
$metadata = $oEntityManager->getClassMetadata(MyTable::class);
$metadata->setPrimaryTable(array('name' => 'MY_TABLE_2019_02')); //-- Dynamically manage the table
echo $metadata->getTableName(); //-- 'MY_TABLE_2019_02' OK
//--
$oMyTable = $oEntityManager->getRepository(MyTable::class);
//--
$aRetour = $oMyTable->myFunction(); //-- SELECT ... FROM MY_TABLE_2019_02... OK
$oMyTable->clear();
//--
$metadata->setPrimaryTable(array('name' => 'MY_TABLE_2019_06')); //-- Dynamically manage the table
echo $metadata->getTableName(); //-- 'MY_TABLE_2019_06' OK !!!!
$aRetour = $oMyTable->myFunction(); //-- SELECT ... FROM MY_TABLE_2019_02... NOK !!!!!!!!! table name not change here !?
symfony4 - Symfony 4 / Doctrine: Dynamic table name on entity => function with find () OK but createQueryBuilder () NOK - Stack Overflow?
|