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?

Thanks!

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-core+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-core/125f930d-73ef-4dab-b353-77a8f2e4280a%40googlegroups.com.

Reply via email to