Symfony use NativeSQL to JOIN unrelated tables
- by keybored
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.