基于连接表列的推进过滤?

时间:2012-06-26 12:41:14

标签: php propel

如何基于Propel中的联接表格列进行过滤?

像:

$results = FooQuery::create()->joinBar()->filterByBarSurname('surname');

1 个答案:

答案 0 :(得分:7)

您必须使用in the doc所述的use方法:

$results = FooQuery::create()
  ->useBarQuery()
    ->filterBySurname('surname')
  ->endUse()
  ->find();

// example Query generated for a MySQL database
$query = 'SELECT foo.* from foo
INNER JOIN bar ON foo.BAR_ID = bar.ID
WHERE bar.SURNAME = :p1'; // :p1 => 'surname'

如果您必须使用join(),我认为您不能使用filterByXXX方法,而是旧版where

$results = FooQuery::create()
  ->join('Foo.Bar')
  ->where('Bar.surname = ?', 'surname')
  ->find();