diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2014-06-06 13:50:10 -0300 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2014-06-06 13:50:10 -0300 |
commit | 16831cd151846cdb2d6dcab88315aa5ecc4e68b6 (patch) | |
tree | 57492bd7a98087b1196c9e5a157152600e3ee306 /README.markdown | |
parent | 6ba88266720049415e91a5348e78657e2f85d848 (diff) | |
parent | ed7ef6baa42434aa4ca52679caf0636754cb27c5 (diff) | |
download | rails-16831cd151846cdb2d6dcab88315aa5ecc4e68b6.tar.gz rails-16831cd151846cdb2d6dcab88315aa5ecc4e68b6.tar.bz2 rails-16831cd151846cdb2d6dcab88315aa5ecc4e68b6.zip |
Merge pull request #285 from vipulnsward/readme-edits
Readme fixes
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: |