aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSean Griffin <sean@seantheprogrammer.com>2017-12-03 16:25:15 -0700
committerGitHub <noreply@github.com>2017-12-03 16:25:15 -0700
commit14a1ad2f5abbb6dc6494ac531dba99d38a178858 (patch)
tree7e2d2c59e78f01612dcae9346f7308dd364beecb
parentc8f014ff1f68bca8deb22f57dd8c7fde9deb7030 (diff)
parent20bb26a428b84ae4f7b09bec284152325b0334f6 (diff)
downloadrails-14a1ad2f5abbb6dc6494ac531dba99d38a178858.tar.gz
rails-14a1ad2f5abbb6dc6494ac531dba99d38a178858.tar.bz2
rails-14a1ad2f5abbb6dc6494ac531dba99d38a178858.zip
Merge pull request #31322 from bogdanvlviv/update-active_record_querying-guide
Update "Active Record Query Interface" guide [ci skip]
-rw-r--r--guides/source/active_record_querying.md18
1 files changed, 9 insertions, 9 deletions
diff --git a/guides/source/active_record_querying.md b/guides/source/active_record_querying.md
index 3786343fc3..4e28e31a53 100644
--- a/guides/source/active_record_querying.md
+++ b/guides/source/active_record_querying.md
@@ -801,7 +801,7 @@ The SQL that would be executed:
SELECT * FROM articles WHERE id > 10 ORDER BY id DESC
# Original query without `only`
-SELECT "articles".* FROM "articles" WHERE (id > 10) ORDER BY id desc LIMIT 20
+SELECT * FROM articles WHERE id > 10 ORDER BY id DESC LIMIT 20
```
@@ -820,14 +820,14 @@ Article.find(10).comments.reorder('name')
The SQL that would be executed:
```sql
-SELECT * FROM articles WHERE id = 10
+SELECT * FROM articles WHERE id = 10 LIMIT 1
SELECT * FROM comments WHERE article_id = 10 ORDER BY name
```
In the case where the `reorder` clause is not used, the SQL executed would be:
```sql
-SELECT * FROM articles WHERE id = 10
+SELECT * FROM articles WHERE id = 10 LIMIT 1
SELECT * FROM comments WHERE article_id = 10 ORDER BY posted_at DESC
```
@@ -1091,7 +1091,7 @@ This produces:
```sql
SELECT articles.* FROM articles
- INNER JOIN categories ON articles.category_id = categories.id
+ INNER JOIN categories ON categories.id = articles.category_id
INNER JOIN comments ON comments.article_id = articles.id
```
@@ -1871,14 +1871,14 @@ All calculation methods work directly on a model:
```ruby
Client.count
-# SELECT count(*) AS count_all FROM clients
+# SELECT COUNT(*) FROM clients
```
Or on a relation:
```ruby
Client.where(first_name: 'Ryan').count
-# SELECT count(*) AS count_all FROM clients WHERE (first_name = 'Ryan')
+# SELECT COUNT(*) FROM clients WHERE (first_name = 'Ryan')
```
You can also use various finder methods on a relation for performing complex calculations:
@@ -1890,9 +1890,9 @@ Client.includes("orders").where(first_name: 'Ryan', orders: { status: 'received'
Which will execute:
```sql
-SELECT count(DISTINCT clients.id) AS count_all FROM clients
- LEFT OUTER JOIN orders ON orders.client_id = clients.id WHERE
- (clients.first_name = 'Ryan' AND orders.status = 'received')
+SELECT COUNT(DISTINCT clients.id) FROM clients
+ LEFT OUTER JOIN orders ON orders.client_id = clients.id
+ WHERE (clients.first_name = 'Ryan' AND orders.status = 'received')
```
### Count