Pregunta

I'm trying to build the where clause using AREL but this does not execute the query:

 rec = self.where('color' => color_passed)
 rec = rec.where('make' => make_passed) if make_passed.present?
 rec = rec.where('year' => year_passed) if year_passed.present?

How can I correctly append the where conditions based on some conditions?

¿Fue útil?

Solución

What do you mean not execute? where only return a Relation object, you have to call all to get the result:

rec.all
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top