【问题标题】:Multiple Propel Like Filters多个类似推进器的过滤器
【发布时间】:2018-09-02 20:33:55
【问题描述】:

尝试使用 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】:

    假设$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

    【讨论】:

    • 完美 - 谢谢! - 另外 ->filterByName($names, Criteria::LIKE) 也可以在这里工作,而不是 where()
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-19
    • 2021-01-12
    • 1970-01-01
    相关资源
    最近更新 更多