Doctrine2:任意连接和单表继承

2022-01-16 00:00:00 php doctrine doctrine-orm

注意:这是一个 ORM 限制在项目的问题跟踪器上报告

Note: This is an ORM limitation reported on the project's issue tracker

我在使用 Doctrine 2.3 中引入的任意连接语法在作为层次结构根的实体类上构建 DQL 查询时遇到问题.

I'm facing an issue building a DQL query using the arbitrary join syntax introduced in Doctrine 2.3 on an entity class which is the root of a hierarchy.

鉴于这些类:

A - 没有继承

B1 - 抽象,层次结构的根,鉴别器列被命名为类型"

B1 - abstract, root of a hierarchy, discriminator column is named 'type'

我设置了一个这样的查询生成器:

I setup a query builder like this:

$qb->select('a.id AS idA, b.id AS idB')
    ->from('EntityA', 'a')
    ->leftJoin('EntityB1', 'b', DoctrineORMQueryExprJoin::WITH, 'a.something=b.something');

SQL Doctrine 生成的内容是这样的:

And the SQL Doctrine generates is something like this:

SELECT a.id, b.id FROM a LEFT JOIN b ON (a.something=b.something) WHERE b.type IN ('1', '2', '3')

问题在于 where 使得 left join 无用.

The problems is that the where makes the left join useless.

有没有办法强制将鉴别器列上的条件放在连接中?至少那会让它...

Is there a way to force the condition on the discriminator column to be placed in the join? At least that would make it...

我应该填写错误报告吗?

Should I fill a bug report?

推荐答案

此错误已在 Doctrine 2.4 中修复

This bug is fixed in Doctrine 2.4

https://github.com/doctrine/doctrine2/issues/2934

相关文章