具有多个数据库的symfony2查询构建器(doctrine)

时间:2015-07-23 10:07:55

标签: php jquery sql symfony doctrine

我想加入abteilung表,该表位于另一个包含其他访问数据的数据库中。

这是abteilung的正确数据库:

$manager = $this->getDoctrine()->getManager('olddb')->getRepository('ChrisOldUserBundle:BpDepartment');

这是我想要更改的旧查询:

$result = $this->getDoctrine()->getRepository('KfzBuchungBundle:Rent')
                ->createQueryBuilder('r')
                ->addSelect('abteilung')
                ->addSelect('auto')
                ->join('r.auto','auto')
                ->join('r.abteilung','abteilung')
                ->where('r.mieteStart >= :date_from')
                ->andWhere('r.mieteEnde <= :date_to')
                ->setParameter('date_from', $date_from)
                ->setParameter('date_to', $date_to)
                ->orderBy('r.mieteStart', 'ASC')
                ->distinct()
                ->getQuery()->getArrayResult();

我尝试过:

$rsm = new ResultSetMapping();
            $rsm->addEntityResult('Chris\KfzBuchungBundle\Entity\Rent', 'bp');
            $rsm->addEntityResult('Chris\Bundle\OldUserBundle\Entity\BpDepartment', 'bp_dpt');
            $rsm->addFieldResult('bp','id','id');
            $query = $this->getDoctrine()->getManager()->createNativeQuery('SELECT * FROM bp_department bp_dpt', $rsm);

            $result = $query->getResult();

但同样糟糕,我不知道。

0 个答案:

没有答案