2

一意のテーブルで 2 つのリクエストを伴うアクションがあります。要求の結果は異なる必要があります。

しかし、結果は私の 2 つの要求で同じであり、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();
4

2 に答える 2

0

生成された 2 つのクエリを比較します。Doctrine 1 でこれをどのように達成できるかわかりません。Doctrine 2 ではロガーを有効にできるため、実行されたすべての SQL は、たとえば stdout に書き込まれます。

もう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();

2 つのステートメントの実行の間に 1 秒以上の遅延が発生する可能性があり、クエリの信頼性が低下します。

于 2010-08-19T13:14:54.737 に答える
0

最善の方法ではないかもしれませんが、1 回のリクエストでテーブルのすべての行を選択するという問題を解決しました。その後、PHP を使用して結果を並べ替えます。

于 2011-03-31T13:59:31.930 に答える