4

如何根据 Propel 中连接表的列进行过滤?

像:

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

1 回答 1

7

您必须使用文档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();
于 2012-06-26T12:47:31.857 回答