Question

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?

Était-ce utile?

La solution

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

rec.all
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top