来自 table 的学说查询构建器 select 不是实体 table
doctrine query builder select from table which is not entity table
我正在努力寻找一种方法来使用查询生成器来 select 来自 table 的数据,而 table 不是某个实体的 table。方法 ->from() 仅将 class 名称(实体名称)作为参数。
类似于:
$qb->select('t.id')
->from('table_not_entity_name')
->andWhere('t.isActive = :isActive')
->setParameter('isActive', 1);
我还需要将一个 table 实体加入另一个 table。
$qb->select('category.id')
->join("t.table_name", 'category')
->distinct();
有办法吗?
不适用于 DQL,您可以使用 NativeQuery。
QueryBuilder class 函数 'from()' 中的注释说:
Creates and adds a query root corresponding to the entity identified
by the given alias, forming a cartesian product with any existing
query roots.
特定于实体。
我正在努力寻找一种方法来使用查询生成器来 select 来自 table 的数据,而 table 不是某个实体的 table。方法 ->from() 仅将 class 名称(实体名称)作为参数。 类似于:
$qb->select('t.id')
->from('table_not_entity_name')
->andWhere('t.isActive = :isActive')
->setParameter('isActive', 1);
我还需要将一个 table 实体加入另一个 table。
$qb->select('category.id')
->join("t.table_name", 'category')
->distinct();
有办法吗?
不适用于 DQL,您可以使用 NativeQuery。
QueryBuilder class 函数 'from()' 中的注释说:
Creates and adds a query root corresponding to the entity identified by the given alias, forming a cartesian product with any existing query roots.
特定于实体。