From af41b98577a09c9177b0fae76b7d07d787d02ce3 Mon Sep 17 00:00:00 2001 From: Krzysztof Maicher Date: Thu, 25 May 2017 14:34:50 +0200 Subject: Add ActiveRecord::Relation#or description to guides [ci skip] --- guides/source/active_record_querying.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'guides/source') diff --git a/guides/source/active_record_querying.md b/guides/source/active_record_querying.md index 26d01d4ede..d1cbe506b4 100644 --- a/guides/source/active_record_querying.md +++ b/guides/source/active_record_querying.md @@ -557,6 +557,19 @@ In other words, this query can be generated by calling `where` with no argument, SELECT * FROM clients WHERE (clients.locked != 1) ``` +### OR Conditions + +`OR` condition between two relations can be build by calling `or` on the first relation +and passing the second one as an argument. + +```ruby +Client.where(locked: true).or(Client.where(orders_count: [1,3,5])) +``` + +```sql +SELECT * FROM clients WHERE (clients.locked = 1 OR clients.orders_count IN (1,3,5)) +``` + Ordering -------- -- cgit v1.2.3