Consider the following simple query:
SELECT * FROM authors WHERE first_name = ‘John’ OR last_name = ‘Smith’
With ActiveRecord you can write it like this:
Author.where(first_name: ‘John’).or(Author.where(last_name: ‘Smith’))
It’s annoying that you need to pass in a whole relation to the
or function. It would be nicer to have something shorter and cleaner. So, I propose to add a
where.or query method, similar to the existing
where.not. This new method would take params in the same way
where does, but instead of using AND as a keyword to join the predicates, it would use OR. The query above would be built as follows:
Author.where.or(first_name: ‘John’, last_name: ‘Smith’)
I’m not sure if I’m missing something fundamental that makes this feature difficult to implement. I’ve actually implemented a working version and I’d be happy to push a PR if the feedback is positive.
Besides the technical challenges that may arise, do you think it’s a useful feature?