简体   繁体   English

doctrine查询构建器从不是实体表的表中选择

[英]doctrine query builder select from table which is not entity table

I am struggling to find a way to use query builder to select data from a table which is not a table of some entity. 我正在努力找到一种方法来使用查询构建器从表中选择数据,该表不是某个实体的表。 method ->from() takes only class name (entity name) as a parameter. method - > from()仅将类名(实体名称)作为参数。 something like: 就像是:

$qb->select('t.id')
   ->from('table_not_entity_name')
   ->andWhere('t.isActive = :isActive')
   ->setParameter('isActive', 1);

I also need to join a table of entity to an another table. 我还需要将实体表连接到另一个表。

$qb->select('category.id')
    ->join("t.table_name", 'category')
    ->distinct();

Is there a way? 有办法吗?

Not with DQL, you can use NativeQuery . 不使用DQL,您可以使用NativeQuery

The comment in function 'from()' at QueryBuilder class says that: QueryBuilder类中函数'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. 创建并添加与给定别名标识的实体对应的查询根,形成具有任何现有查询根的笛卡尔积。

Is specific for an entity. 特定于实体。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM