diff options
author | Yves Senn <yves.senn@gmail.com> | 2013-11-24 23:56:32 -0800 |
---|---|---|
committer | Yves Senn <yves.senn@gmail.com> | 2013-11-24 23:56:32 -0800 |
commit | 9dc89f3fc425af5cfc5fa5ea3809e554db017653 (patch) | |
tree | 5de913070d833593e87a725f9589639fdd177cfc /guides/source | |
parent | 587c2d67ce3279f79b00a23db9c2f42ae59af548 (diff) | |
parent | 66087189c1aa14b91383c25fcf8762bb58c6e2b3 (diff) | |
download | rails-9dc89f3fc425af5cfc5fa5ea3809e554db017653.tar.gz rails-9dc89f3fc425af5cfc5fa5ea3809e554db017653.tar.bz2 rails-9dc89f3fc425af5cfc5fa5ea3809e554db017653.zip |
Merge pull request #13026 from vipulnsward/document_rewhere
Added `rewhere` usage to AR querying guides
Diffstat (limited to 'guides/source')
-rw-r--r-- | guides/source/active_record_querying.md | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/guides/source/active_record_querying.md b/guides/source/active_record_querying.md index bdfcfd92ce..94b8453f04 100644 --- a/guides/source/active_record_querying.md +++ b/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 ------------- |