Symfony use NativeSQL to JOIN unrelated tables

Posted by keybored on Stack Overflow See other posts from Stack Overflow or by keybored
Published on 2013-11-05T21:52:07Z Indexed on 2013/11/05 21:53 UTC
Read the original article Hit count: 150

Filed under:
|

I'd like to run a query like this:

$rsm = new ResultSetMappingBuilder($this->em);
$rsm->addRootEntityFromClassMetadata('myBundle:Foo', 'f');
$rsm->addRootEntityFromClassMetadata('myBundle:Bar', 'b');

$sql = 'SELECT l.*, b.*  FROM foos f
        INNER JOIN FROM bars b
        ON b.baz_id = f.baz_id
        WHERE l.bam = 1';

$query = $this->em->createNativeQuery($sql, $rsm);
$fooBarQuery= $query->getResult();

Unfortunately this is not a situation where I can set up a proper relationship in the entity. Is not going to be possible for me to do this? Thanks.

© Stack Overflow or respective owner

Related posts about sql

Related posts about symfony2