j4mie / idiorm

A lightweight nearly-zero-configuration object-relational mapper and fluent query builder for PHP5.
http://j4mie.github.com/idiormandparis/
2.01k stars 369 forks source link

Is there any method like where_any_is but using like? #276

Closed rosorrentino closed 9 years ago

rosorrentino commented 9 years ago

HI, I am looking in documentation for a option as where_any_is or where_in but to use as “like” so I can use wildcards in the search values (same as use WHERE x LIKE y OR x LIKE z);

I think this methods “where_any_is" or “where_in" are very useful since we can give arrays and the number of inputs are variable.

JoN1oP commented 9 years ago

Hi @rosorrentino, This is how I solved this particular problem. I created a filter on my model.

static function search($orm, $search = '') {
  if(strlen(trim($search) === 0)) {
    return $orm;
  }

  return $orm->where_raw(
    '(`email` LIKE ? OR `first_name` LIKE ? OR `last_name` LIKE ?)',
    array('%'.$search.'%', '%'.$search.'%', '%'.$search.'%')
  );
}
rosorrentino commented 9 years ago

Thanks, I will try that, much appreciate it.

treffynnon commented 9 years ago

This is the route to do this kind of thing with Idiorm.