You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
we have multiple large tables refering to the same entity. For the purpose of this discussion let's call it Stat.
the tables are named like this : stat_2023_08, stat_2023_09 ...
To handle this usecase we firstly used the following workaround to set table's name at runtime :
We noticed that it doesn't works in only one method despite the code is identical in others methods, quite strange.
When we inspect the SQL, the name is updated.
SqlWalker feature is quite new to us so we're a bit lost right now.
Any ideas / thoughs to help us investigate the issue please ?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hello,
we have multiple large tables refering to the same entity. For the purpose of this discussion let's call it Stat.
the tables are named like this : stat_2023_08, stat_2023_09 ...
To handle this usecase we firstly used the following workaround to set table's name at runtime :
$this->getEntityManager()->clear();
$this->getEntityManager()->getClassMetadata(Stat::class)->setPrimaryTable(['name' => 'stat_'.$year.'_'.sprintf('%02d', $month)]);
...
building query...
return $qb->getQuery()->expireQueryCache()->getSingleResult();
Then we found this other SqlWalker's based workaround (#6240) :
class FromTableWalkerBis extends SqlWalker {
public function walkSelectStatement(SelectStatement $ast) {
$sql = parent::walkSelectStatement($ast);
return str_replace($this->getQuery()->getHint('oldTableName'), $this->getQuery()->getHint('newTableName'), $sql);
}
}
$baseTableName = $this->getEntityManager()->getClassMetadata(Stat::class)->getTableName();
... building query ...
$query = $qb->getQuery();
$query->setHint('oldTableName', $baseTableName);
$query->setHint('newTableName', $baseTableName.'_'.$year.'_'.sprintf('%02d', $month));
$query->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, 'App\\Repository\\SqlWalker\\FromTableWalker');
return $query->getSingleResult();
We noticed that it doesn't works in only one method despite the code is identical in others methods, quite strange.
When we inspect the SQL, the name is updated.
SqlWalker feature is quite new to us so we're a bit lost right now.
Any ideas / thoughs to help us investigate the issue please ?
Thanks
Beta Was this translation helpful? Give feedback.
All reactions