From de75af7acc5c05c708443de40e78965925165217 Mon Sep 17 00:00:00 2001 From: Akira Matsuda Date: Mon, 5 Nov 2012 13:56:30 +0900 Subject: Relation.where with no args can be chained with not, like, and not_like examples: Model.where.not field: nil #=> "SELECT * FROM models WHERE field IS NOT NULL Model.where.like name: 'Jeremy%' #=> "SELECT * FROM models WHERE name LIKE 'Jeremy%' this feature was originally suggested by Jeremy Kemper https://github.com/rails/rails/pull/5950#issuecomment-5591330 Closes #5950 --- guides/source/active_record_querying.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'guides') diff --git a/guides/source/active_record_querying.md b/guides/source/active_record_querying.md index 32c139df99..5a4e084ce2 100644 --- a/guides/source/active_record_querying.md +++ b/guides/source/active_record_querying.md @@ -503,6 +503,20 @@ This code will generate SQL like this: SELECT * FROM clients WHERE (clients.orders_count IN (1,3,5)) ``` +### NOT, LIKE, and NOT LIKE Conditions + +`NOT`, `LIKE`, and `NOT LIKE` SQL queries can be built by `where.not`, `where.like`, and `where.not_like` respectively. + +```ruby +Post.where.not(author: author) + +Author.where.like(name: 'Nari%') + +Developer.where.not_like(name: 'Tenderl%') +``` + +In other words, these sort of queries can be generated by calling `where` with no argument, then immediately chain with `not`, `like`, or `not_like` passing `where` conditions. + Ordering -------- -- cgit v1.2.3