aboutsummaryrefslogtreecommitdiffstats
path: root/guides/source
diff options
context:
space:
mode:
authorCarlos Antonio da Silva <carlosantoniodasilva@gmail.com>2013-11-19 10:46:34 -0200
committerCarlos Antonio da Silva <carlosantoniodasilva@gmail.com>2013-11-19 10:46:55 -0200
commitdb3ec5183258fae55ba6d5335cbdbb82f61818b7 (patch)
tree948ba7ac06a05e3bb40c6ef5a7a6762b7ad7d7a4 /guides/source
parentac35f72f30c47298a20a90c8c537db888b463bbb (diff)
downloadrails-db3ec5183258fae55ba6d5335cbdbb82f61818b7.tar.gz
rails-db3ec5183258fae55ba6d5335cbdbb82f61818b7.tar.bz2
rails-db3ec5183258fae55ba6d5335cbdbb82f61818b7.zip
Revert last two commits mistakenly changing join/include syntax
--- Revert "syntax error joining/including models" This reverts commit ac35f72f30c47298a20a90c8c537db888b463bbb. --- Revert "syntax error joining tables" This reverts commit c365986b48c3e8bc8c7f3fa6a8521616ed5dc138. --- Comments: https://github.com/rails/docrails/commit/c365986b48c3e8bc8c7f3fa6a8521616ed5dc138#commitcomment-4630684
Diffstat (limited to 'guides/source')
-rw-r--r--guides/source/active_record_querying.md14
1 files changed, 7 insertions, 7 deletions
diff --git a/guides/source/active_record_querying.md b/guides/source/active_record_querying.md
index 0f9b2c28a5..57e8e080f4 100644
--- a/guides/source/active_record_querying.md
+++ b/guides/source/active_record_querying.md
@@ -473,7 +473,7 @@ In the case of a belongs_to relationship, an association key can be used to spec
```ruby
Post.where(author: author)
-Author.joins(:post).where(posts: {author: author})
+Author.joins(:posts).where(posts: {author: author})
```
NOTE: The values cannot be symbols. For example, you cannot do `Client.where(status: :active)`.
@@ -975,7 +975,7 @@ Now all of the following will produce the expected join queries using `INNER JOI
#### Joining a Single Association
```ruby
-Category.joins(:post)
+Category.joins(:posts)
```
This produces:
@@ -990,7 +990,7 @@ Or, in English: "return a Category object for all categories with posts". Note t
#### Joining Multiple Associations
```ruby
-Post.joins(:category, :comment)
+Post.joins(:category, :comments)
```
This produces:
@@ -1041,14 +1041,14 @@ You can specify conditions on the joined tables using the regular [Array](#array
```ruby
time_range = (Time.now.midnight - 1.day)..Time.now.midnight
-Client.joins(:order).where('orders.created_at' => time_range)
+Client.joins(:orders).where('orders.created_at' => time_range)
```
An alternative and cleaner syntax is to nest the hash conditions:
```ruby
time_range = (Time.now.midnight - 1.day)..Time.now.midnight
-Client.joins(:order).where(orders: {created_at: time_range})
+Client.joins(:orders).where(orders: {created_at: time_range})
```
This will find all clients who have orders that were created yesterday, again using a `BETWEEN` SQL expression.
@@ -1101,7 +1101,7 @@ Active Record lets you eager load any number of associations with a single `Mode
#### Array of Multiple Associations
```ruby
-Post.includes(:category, :comment)
+Post.includes(:category, :comments)
```
This loads all the posts and the associated category and comments for each post.
@@ -1121,7 +1121,7 @@ Even though Active Record lets you specify conditions on the eager loaded associ
However if you must do this, you may use `where` as you would normally.
```ruby
-Post.includes(:comment).where("comments.visible" => true)
+Post.includes(:comments).where("comments.visible" => true)
```
This would generate a query which contains a `LEFT OUTER JOIN` whereas the `joins` method would generate one using the `INNER JOIN` function instead.