Permalink
Browse files

Merge pull request #13026 from vipulnsward/document_rewhere

Added `rewhere` usage to AR querying guides
  • Loading branch information...
2 parents 587c2d6 + 6608718 commit 9dc89f3fc425af5cfc5fa5ea3809e554db017653 @senny senny committed Nov 25, 2013
Showing with 26 additions and 0 deletions.
  1. +26 −0 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
-------------

0 comments on commit 9dc89f3

Please sign in to comment.