diff options
author | Vipul A M <vipulnsward@gmail.com> | 2014-06-06 21:53:08 +0530 |
---|---|---|
committer | Vipul A M <vipulnsward@gmail.com> | 2014-06-06 22:15:58 +0530 |
commit | ed7ef6baa42434aa4ca52679caf0636754cb27c5 (patch) | |
tree | 2563ae8038b9189cd01e950ffda1af904af40155 /README.markdown | |
parent | 8eb2a7a75bc977b9c4c8311952a142dfa1565238 (diff) | |
download | rails-ed7ef6baa42434aa4ca52679caf0636754cb27c5.tar.gz rails-ed7ef6baa42434aa4ca52679caf0636754cb27c5.tar.bz2 rails-ed7ef6baa42434aa4ca52679caf0636754cb27c5.zip |
- Fixes to readme grammar
- Fixed example and corresponding out interpretation
[ci-skip]
Diffstat (limited to 'README.markdown')
-rw-r--r-- | README.markdown | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/README.markdown b/README.markdown index 75b0b3ee0b..f12aa67498 100644 --- a/README.markdown +++ b/README.markdown @@ -160,7 +160,7 @@ products. #### Complex Joins -Where Arel really shines in its ability to handle complex joins and aggregations. As a first example, let's consider an "adjacency list", a tree represented in a table. Suppose we have a table `comments`, representing a threaded discussion: +Where Arel really shines is in its ability to handle complex joins and aggregations. As a first example, let's consider an "adjacency list", a tree represented in a table. Suppose we have a table `comments`, representing a threaded discussion: ```ruby comments = Arel::Table.new(:comments) @@ -172,16 +172,17 @@ And this table has the following attributes: # [:id, :body, :parent_id] ``` -The `parent_id` column is a foreign key from the `comments` table to itself. Now, joining a table to itself requires aliasing in SQL. In fact, you may alias in Arel as well: +The `parent_id` column is a foreign key from the `comments` table to itself. +Joining a table to itself requires aliasing in SQL. This aliasing can be handled from Arel as below: ```ruby replies = comments.alias comments_with_replies = \ - comments.join(replies).on(replies[:parent_id].eq(comments[:id])) -# => SELECT * FROM comments INNER JOIN comments AS comments_2 WHERE comments_2.parent_id = comments.id + comments.join(replies).on(replies[:parent_id].eq(comments[:id])).where(comments[:id].eq(1)) +# => SELECT * FROM comments INNER JOIN comments AS comments_2 WHERE comments_2.parent_id = comments.id AND comments.id = 1 ``` -This will return the first comment's reply's body. +This will return the reply for the first comment. [Common Table Expresssions(CTE)](https://en.wikipedia.org/wiki/Common_table_expressions#Common_table_expression) support via: |