vendredi 27 novembre 2020

Ruby on Rails - Criteria - Mongoid - where condition with 2 by 2 columns

I'm working with RoR + MongoDB (Mongoid) and I need to apply a filter using or condition by 2 columns.

I saw some recommendations like this one but didn't work.

query = query.where(name: /#{attributes[:name]}/i).or(query.where(email: /#{attributes[:email]}/i))

If I use this one, looks like the or will be applied for all conditions:

query = query.where(name: /#{attributes[:name]}/i).or(email: /#{attributes[:email]}/i)

Anyone has any suggestion?

Aucun commentaire:

Enregistrer un commentaire