2010-08-19 1 views
2

고유 테이블에 대한 두 가지 요청이있는 작업이 있습니다. 요청 결과는 달라야합니다.하나의 작업에서 테이블에 대한 두 요청에 대한 문제

그러나 내 두 요청에 대한 결과는 동일하며 두 번째 요청에서 온 것입니다.

// Récupération du (ou des) locataire(s) actuel(s) du logement 
    $this->locataires = Doctrine_Query::create() 
     ->from('logement l') 
     ->leftJoin('l.Bail b') 
     ->leftJoin('b.Locataire') 
     ->where('l.id = ?', $request->getParameter('id')) 
     ->andWhere('(b.datefin >= ?', date('Y-m-d', time())) 
     ->orWhere("b.datefin = '0000-00-00')") 
     ->execute(); 

    // Récupération du (ou des) locataire(s) précédent(s) du logement 
    $this->locatairesprec = Doctrine_Query::create() 
     ->from('logement l') 
     ->leftJoin('l.Bail b') 
     ->leftJoin('b.Locataire') 
     ->where('l.id = ?', $request->getParameter('id')) 
     ->andWhere('b.datefin < ?', date('Y-m-d', time())) 
     ->andWhere("b.datefin != '0000-00-00'") 
     ->orderBy('datedeb') 
     ->execute(); 
+0

이 PHP이다 사용하여 결과를 정렬? 그렇다면 태그하십시오. – leppie

+0

ID로 선택하고 ID는 두 검색어에서 동일합니다. 왜 그것이 다른 결과를 가져올 것이라고 기대합니까? –

+0

PHP 나 SQL이 아닙니다. 그것은 교리입니다. –

답변

0

그것은 아마 가장 좋은 방법,하지만 난 하나 개의 요청에 내 테이블의 모든 행을 선택하는 문제를 해결할 수 있고, 후에, 나는 PHP

0

생성되는 두 개의 쿼리를 비교하십시오. 나는 Doctrine 1에서 이것을 어떻게 달성 할 수 있는지 모르겠다. Doctrine 2에서 로거를 사용할 수 있으므로, 실행 된 모든 SQL은 예를 들어 stdout에 기록된다.

다른 하나.

현재 시간 소인을 조회에 사용하면 현재 시간 소인으로 변수를 정의하고 두 조회에서이 변수를 사용합니다.

$currentTime = time(); 

// Récupération du (ou des) locataire(s) actuel(s) du logement 
$this->locataires = Doctrine_Query::create() 
    ->from('logement l') 
    ->leftJoin('l.Bail b') 
    ->leftJoin('b.Locataire') 
    ->where('l.id = ?', $request->getParameter('id')) 
    ->andWhere('(b.datefin >= ?', $currentTime) 
    ->orWhere("b.datefin = '0000-00-00')") 
    ->execute(); 

// Récupération du (ou des) locataire(s) précédent(s) du logement 
$this->locatairesprec = Doctrine_Query::create() 
    ->from('logement l') 
    ->leftJoin('l.Bail b') 
    ->leftJoin('b.Locataire') 
    ->where('l.id = ?', $request->getParameter('id')) 
    ->andWhere('b.datefin < ?', $currentTime) 
    ->andWhere("b.datefin != '0000-00-00'") 
    ->orderBy('datedeb') 
    ->execute(); 

(더 후)의 지연 쿼리가 신뢰할 수없는하게 두 문장의 실행 사이의 제있을 수있다 :이 경우에는 같은 것이 될 것이다.

+0

감사합니다. 나는 이것을 시도 할 것이다. 괄호에 대해서는 이전에 열었습니다.) – Elorfin

관련 문제