1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Added rewhere usage to AR querying guides

This commit is contained in:
Vipul A M 2013-11-25 12:00:46 +05:30
parent 587c2d67ce
commit 66087189c1

View file

@ -790,6 +790,32 @@ SELECT * FROM clients WHERE orders_count > 10 ORDER BY clients.id DESC
This method accepts **no** arguments. 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 Null Relation
------------- -------------