多个类似于推进器的过滤器

时间:2018-08-31 23:48:12

标签: php symfony propel

尝试使用LIKE按多种条件过滤列。

赞:

$d = ItemQuery::create()
                ->filterByName($array_of_names, Criteria::LIKE)
                ->find();

但是我得到“ propel / src / Propel / Runtime / Connection / StatementWrapper.php中的数组到字符串的转换”

如何使用“喜欢”条件按多个“名称”过滤?

我基本上希望查询成为

...name LIKE %name1% OR name LIKE %name2% OR name LIKE %name2%...

1 个答案:

答案 0 :(得分:1)

假设$array_of_names[$name1, $name2, ...]

$q = ItemQuery::create()

foreach ($array_of_names as $i => $name) {
    if ($i > 0) { // Not the first item in the array
        $q->_or();
    }

    $q->where('Item.Name LIKE %?%', $name);
}

$d = $q->find();

请参见

http://propelorm.org/blog/2012/03/20/don-t-do-this-at-home-5-use-where-instead-of-filterby.html

http://propelorm.org/blog/2011/02/21/using-or-in-propel-queries-becomes-much-easier-with-propel-1-6.html

https://github.com/propelorm/Propel/issues/120