diff options
author | Carlos Antonio da Silva <carlosantoniodasilva@gmail.com> | 2013-11-19 10:54:46 -0200 |
---|---|---|
committer | Carlos Antonio da Silva <carlosantoniodasilva@gmail.com> | 2013-11-19 10:54:46 -0200 |
commit | 20d3484f32f22b6775f3ff6e8983c5bc021855eb (patch) | |
tree | 63ad2896f5817bbfea51c5238a2dd1686195a842 /guides | |
parent | db3ec5183258fae55ba6d5335cbdbb82f61818b7 (diff) | |
download | rails-20d3484f32f22b6775f3ff6e8983c5bc021855eb.tar.gz rails-20d3484f32f22b6775f3ff6e8983c5bc021855eb.tar.bz2 rails-20d3484f32f22b6775f3ff6e8983c5bc021855eb.zip |
Improve reading / style of hashes in AR guide
Diffstat (limited to 'guides')
-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 57e8e080f4..43160025f0 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)`. @@ -1022,7 +1022,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: @@ -1048,7 +1048,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. @@ -1109,7 +1109,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. @@ -1610,7 +1610,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: |