Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Browse files

Improve reading / style of hashes in AR guide

  • Loading branch information...
commit 20d3484f32f22b6775f3ff6e8983c5bc021855eb 1 parent db3ec51
@carlosantoniodasilva carlosantoniodasilva authored
Showing with 5 additions and 5 deletions.
  1. +5 −5 guides/source/
10 guides/source/
@@ -473,7 +473,7 @@ In the case of a belongs_to relationship, an association key can be used to spec
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)
-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:
time_range = ( -
-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
-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:
-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:

0 comments on commit 20d3484

Please sign in to comment.
Something went wrong with that request. Please try again.