0

この結合に where 条件を追加し$x->getTable1()->getTable2()て、このクエリと同じ結果を得ることはできますか?

$y = Doctrine_Query::create()  
      ->from('Table0 t0')
      ->innerJoin('t0.Table1 t1')
      ->innerJoin('t1.Table2 t2')
      ->where('t2.status = "active"')
      ->execute->getLast();
4

1 に答える 1

0

カスタム メソッドを作成する必要があります。普段はこんな感じでやっています。

Table1.class.php で、カスタム メソッドを作成します。

public function getTable2ByStatus($status = 'active')
{
  return Doctrine_Core::getTable('Table2')->retrieveByStatus($status);
}

次に、Table2Table.class.php で:

public function retrieveByStatus($status)
{
  return $this->createQuery('t2')
    ->where('t2.status = ?', $status)
    ->execute()
    ->getLast();
}

これで、次のように呼び出すことができます。

$x->getTable1()->getTable2ByStatus();
于 2013-01-15T09:37:54.387 に答える