現在のDoctrine設定に問題があります。単一のエンティティ上の複数のテーブル
一意のエンティティを複数の生成テーブルにマップしたいとします。 私はそれが標準的な使い方ではないことを知っていますが、私たちの制約はいくつかの最適化を必要とし、我々はアカウントごとにテーブルを分割する必要があります。
各クエリの前に、クラスマッププロパティのsetPrimaryTableを呼び出して、リポジトリテーブル名を更新しようとしました。しかし、最初の実行後にテーブルを更新することはできないようです。
の作業例:
$em = $this->getDoctrine()->getManager();
$productM = $em->getRepository('DataBundle:Product');
$classMetaData = $em->getClassMetadata('DataBundle:Product');
$classMetaData->setPrimaryTable(['name' => 'product_copy']);
$productM->findAll(); // select * from product_copy;
問題の場合:
$em = $this->getDoctrine()->getManager();
$productM = $em->getRepository('DataBundle:Product');
$classMetaData = $em->getClassMetadata('DataBundle:Product');
$productM->findAll(); // select * from product;
$classMetaData->setPrimaryTable(['name' => 'product_copy']);
$productM->findAll(); // select * from product;
教義の哲学に準拠するように、このケースを処理するための適切な解決策はありますか?少なくとも可能ですか?
ASTウォーカーを使用してGidmoコードに他の "解決策"を掘り下げましたが、それは他のCRUD操作ではなく選択されたケースのみを処理できます。
class FromWalker extends SqlWalker {
public function walkRangeVariableDeclaration($rangeVariableDeclaration)
{
$sql = parent::walkRangeVariableDeclaration($rangeVariableDeclaration);
// replace the table name by a custom one
return $sql;
}
}