0
Doctrine DQLでは、逆マッピングを使用しているエンティティなしで多対多の関連付けからカウントを取得しようとしています。 。逆マッピングなしでDoctrineの逆オブジェクトから多くのオブジェクトへの関連の数を取得する
$this->getEntityManager()->createQueryBuilder()
->select('a AS attribute')
->addSelect('COUNT(p) AS num_products')
->from('VendorAttributeBundle:Attribute', 'a')
->leftJoin('VendorProductBundle:Product', 'p', 'WITH', 'a MEMBER OF p.attributes')
->groupBy('a.id');
以上実行されますがnum_products
フィールドの0
返します。
私はbiderectional多対多エンティティに対してクエリを実行し、うまく機能します。マッピングでエラーを見つけようとします。私の例を見てください。https://gist.github.com/Infernosquad/cc6237e7c782892e70ba33dd36976234 –