diff options
author | Xavier Noria <fxn@hashref.com> | 2013-11-24 20:00:24 +0100 |
---|---|---|
committer | Xavier Noria <fxn@hashref.com> | 2013-11-24 20:00:24 +0100 |
commit | 17c29a0df0da5414570b025b642e90968e96cddc (patch) | |
tree | de1fd00eb2df79bf6bdcaeb74cc17365eaa53e33 /guides/source/active_record_querying.md | |
parent | b4b30c048d22b14d51cc2f0f5b397bf899a9ce49 (diff) | |
parent | 28a6a7ea3bd627a8b6693a4cb8305b89467592b4 (diff) | |
download | rails-17c29a0df0da5414570b025b642e90968e96cddc.tar.gz rails-17c29a0df0da5414570b025b642e90968e96cddc.tar.bz2 rails-17c29a0df0da5414570b025b642e90968e96cddc.zip |
Merge remote-tracking branch 'docrails/master'
Conflicts:
activesupport/lib/active_support/core_ext/hash/deep_merge.rb
activesupport/lib/active_support/core_ext/hash/keys.rb
Diffstat (limited to 'guides/source/active_record_querying.md')
-rw-r--r-- | guides/source/active_record_querying.md | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/guides/source/active_record_querying.md b/guides/source/active_record_querying.md index b518a086be..bdfcfd92ce 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(:posts).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)`. @@ -1016,7 +1016,7 @@ Or, in English: "return all posts that have a comment made by a guest." #### Joining Nested Associations (Multiple Level) ```ruby -Category.joins(posts: [{comments: :guest}, :tags]) +Category.joins(posts: [{ comments: :guest }, :tags]) ``` This produces: @@ -1042,7 +1042,7 @@ An alternative and cleaner syntax is to nest the hash conditions: ```ruby time_range = (Time.now.midnight - 1.day)..Time.now.midnight -Client.joins(:orders).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. @@ -1103,7 +1103,7 @@ This loads all the posts and the associated category and comments for each post. #### Nested Associations Hash ```ruby -Category.includes(posts: [{comments: :guest}, :tags]).find(1) +Category.includes(posts: [{ comments: :guest }, :tags]).find(1) ``` This will find the category with id 1 and eager load all of the associated posts, the associated posts' tags and comments, and every comment's guest association. @@ -1604,7 +1604,7 @@ Client.where(first_name: 'Ryan').count You can also use various finder methods on a relation for performing complex calculations: ```ruby -Client.includes("orders").where(first_name: 'Ryan', orders: {status: 'received'}).count +Client.includes("orders").where(first_name: 'Ryan', orders: { status: 'received' }).count ``` Which will execute: |