Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #13026 from vipulnsward/document_rewhere

Added `rewhere` usage to AR querying guides
  • Loading branch information...
commit 9dc89f3fc425af5cfc5fa5ea3809e554db017653 2 parents 587c2d6 + 6608718
@senny senny authored
Showing with 26 additions and 0 deletions.
  1. +26 −0 guides/source/active_record_querying.md
View
26 guides/source/active_record_querying.md
@@ -790,6 +790,32 @@ SELECT * FROM clients WHERE orders_count > 10 ORDER BY clients.id DESC
This method accepts **no** arguments.
+### `rewhere`
+
+The `rewhere` method overrides an existing, named where condition. For example:
+
+```ruby
+Post.where(trashed: true).rewhere(trashed: false)
+```
+
+The SQL that would be executed:
+
+```sql
+SELECT * FROM posts WHERE `trashed` = 0
+```
+
+In case the `rewhere` clause is not used,
+
+```ruby
+Post.where(trashed: true).where(trashed: false)
+```
+
+the SQL executed would be:
+
+```sql
+SELECT * FROM posts WHERE `trashed` = 1 AND `trashed` = 0
+```
+
Null Relation
-------------
Please sign in to comment.
Something went wrong with that request. Please try again.