-1
나는 며칠 동안 dql 문제로 작업 해 왔습니다.쿼리 작성기의 Dql
내 모델에는 y 엔티티 (기계 및 인스턴스)가 2 개 있습니다. 일대 다 관계이므로 기계가 많은 인스턴스를 가질 수 있고 인스턴스는 기계 만 가질 수 있습니다.
이제 인스턴스가있는 모든 시스템을 가져오고 싶습니다.
$ids = array(...)
$dql = "select M from AppBundle:Machine M INNER JOIN AppBundle:Instancia I WITH M.id = I.machine WHERE I.software IN (:ids)";
$query = $em->createQuery($dql)->setParameter('ids', $ids);
$maquinas = $query->getResult();
을하지만 난이 일을 못하고 있어요 QueryBuilder에서 번역 할 때 정상 DQL에서 나는 그렇게 제대로 작동 얻을. 몇 가지 방법을 삼키고 있습니다.
//First way
$qb = $this->createQueryBuilder("M")
->innerJoin('Instancia', 'I', 'WITH', 'M.id = I.machine')
->where('I.software IN (:ids)')
->setParameters('ids', $ids);
$maquinas = $qb->getQuery()->getResult();
//Second way
$qb = $this->createQueryBuilder("x")
->select('M')
->from('AppBundle:Machine', 'M')
->innerJoin('Instancia', 'I', 'WITH', 'M.id = I.machine')
->where('I.software IN (:ids)')
->setParameters('ids', $ids);
$maquinas = $qb->getQuery()->getResult();
내 잘못이 무엇입니까?
더 빠른, 간단한 dql 또는 querybuilder는 어느 방법입니까 ??
감사합니다.
당신은 어떤 오류가있다? –
이 오류가 발생합니다. 치명적인 오류 : __clone 메서드가 아닌 개체에 대한 호출 – Angel
dql statment에서 where 절을 추가 할 수 있습니까? 예 : $ dql = "AppBundle에서 M 선택 : Maquina M INNER JOIN AppBundle : Instancia I WITH M.id = I.maquina"; $ query = $ em-> createQuery ($ dql); $ query-> where ("I.software IN (: ids)"); $ query-> setParameter ('ids', $ ids); – Angel