activerecord - OR clause in Rails 5 -
how can (a || b) && ( c || d) query in rails 5 activerecord?. tried post.where(a).or(post.where(b)).where(c).or(post.where(d))
but produces as: (a || b) && c || d. correct code desired query?
the rails or()
method not complex this. there long discussion feature when first proposed here, on github
this method meant provide convenient way of railsifying queries, sometimes, things cannot simple. or()
method stuck reading left-to-right.
your best bet while sticking "railsy" convention follow 1 of following approaches:
post.where("a or b").where("c or d") # example 1 - sql additional where() post.where(a: [true, !b]).where(c: [true, !d]) # example 2 - array comparison post.where("(a or b) , (c or d)") # example 3 - sql
Comments
Post a Comment