Reputation: 453
Trying to filter a column by multiple conditions using LIKE.
Like this:
$d = ItemQuery::create()
->filterByName($array_of_names, Criteria::LIKE)
->find();
But I get "Array to string conversion in propel/src/Propel/Runtime/Connection/StatementWrapper.php"
How can I filter by multiple "names" using the "LIKE" criteria?
I basically want the query to be
...name LIKE %name1% OR name LIKE %name2% OR name LIKE %name2%...
Upvotes: 1
Views: 1778
Reputation: 713
Assuming that $array_of_names
is [$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();
See
http://propelorm.org/blog/2012/03/20/don-t-do-this-at-home-5-use-where-instead-of-filterby.html
and
or
https://github.com/propelorm/Propel/issues/120
Upvotes: 1