多个推进式过滤器

问题描述 投票:1回答:1

尝试使用LIKE按多个条件筛选列。

像这样:

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

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

如何使用“LIKE”标准按多个“名称”进行过滤?

我基本上想要查询

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

php symfony propel
1个回答
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

© www.soinside.com 2019 - 2024. All rights reserved.