我在唯一表上有两个请求的动作。请求的结果必须不同。

但是,我的两个请求的结果是相同的,它来自我的第二个请求。

    // 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();
有帮助吗?

解决方案 2

这也许不是最好的方法,但是我解决了一个问题,以在一个请求中选择表的所有行,之后,我使用PHP对结果进行排序

其他提示

比较其生成的两个查询。我不知道如何在学说1中完成此操作。

另一件事。

当您在查询中使用当前的时间戳时,您会用当前时间戳定义一个变量,并在两个查询中使用此变量。在这种情况下,它将像:

$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();

在两个语句的执行之间可能会延迟(更多)一秒钟,这使您的查询不可靠。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top