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

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -