Несколько Propel Like Filters - PullRequest
       27

Несколько Propel Like Filters

0 голосов
/ 01 сентября 2018

Попытка отфильтровать столбец по нескольким условиям, используя 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%...

1 Ответ

0 голосов
/ 02 сентября 2018

Предполагая, что $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

...