There are 5 options that could be considered as implementations of «Hash notation» (the last two are kinda hash-ish):
-
With Ruby on Rails 5 you are able to do the following chaining using
ActiveRecord::Relation#ormethod:Person.where(name: 'Neil').or(Person.where(age: 27)) -
Use
where_valuestogether withreduce. Theunscopedmethod is necessary only for Rails 4.1+ to ensuredefault_scopeis not included in thewhere_values. Otherwise predicates from bothdefault_scopeandwherewould be chained with theoroperator:Person.where( Person.unscoped.where(name: ['Neil'], age: [27]).where_values.reduce(:or) ) -
Install third-party plugins that implement these or similar features, for example:
-
Where Or (backport of the Ruby on Rails 5
.orfeature mentioned above) -
Squeel
Person.where{(name == 'Neil') | (age == 27)} -
RailsOr
Person.where(name: 'Neil').or(age: 27) -
ActiverecordAnyOf
Person.where.anyof(name: 'Neil', age: 27) -
SmartTuple
Person.where( (SmartTuple.new(' or ') << {name: 'Neil', age: 27}).compile )
-
-
Use Arel:
Person.where( Person.arel_table[:name].eq('Neil').or( Person.arel_table[:age].eq(27) ) ) -
Use prepared statements with named parameters:
Person.where('name = :name or age = :age', name: 'Neil', age: 27)