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:
parent
587c2d67ce
commit
66087189c1
1 changed files with 26 additions and 0 deletions
|
@ -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
|
||||
-------------
|
||||
|
||||
|
|
Loading…
Reference in a new issue