Permalink
Browse files

Added `rewhere` usage to AR querying guides

  • Loading branch information...
1 parent 587c2d6 commit 66087189c1aa14b91383c25fcf8762bb58c6e2b3 @vipulnsward vipulnsward 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 6608718

Please sign in to comment.