Use Doctrine createQueryBuilder with tablets that have no entity

Asked

Viewed 19 times

0

It is possible to perform a query with Doctrine createQueryBuilder using a table that does not have a declared entity (Entity)?

Example: In the code below table table2 (t2) does not have an entity created, because it is a relationship table and only has the relation fields.

$this->createQueryBuilder('t1')
     ->select(['t1', 't2.id'])
     ->leftJoin('table2', 't2', 'ON', 't1.id = t2.id')
     ->andWhere('t2.id IS NOT NULL')
     ->getQuery()
     ->getResult();
  • When it’s relationship you don’t even need to do a custom query, just give a get of the property in Entity. But if for some reason it is necessary you just put in select to return t1.t2 ( where t2 is the name of the property in Entity t1).

1 answer

0

Browser other questions tagged

You are not signed in. Login or sign up in order to post.