From 27a7af81bd274f8036f42638acdb47e85e76c5aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sylvain=20Ab=C3=A9lard?= Date: Sun, 15 Oct 2017 20:30:27 +0200 Subject: Update README.md * s/crazy/advanced/ to avoid ableist words * last sections didn't have titles to separate topics I have written a bit more examples of "less trivial" Arel code here, perhaps we can add some of that here: https://github.com/rstacruz/cheatsheets/pull/92/files --- README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'README.md') diff --git a/README.md b/README.md index af768361ab..065bfea26c 100644 --- a/README.md +++ b/README.md @@ -188,7 +188,7 @@ users.project(users[:age].average.as("mean_age")) # => SELECT AVG(users.age) AS mean_age FROM users ``` -### The Crazy Features +### The Advanced Features The examples above are fairly simple and other libraries match or come close to matching the expressiveness of Arel (e.g. `Sequel` in Ruby). @@ -215,6 +215,7 @@ products. #### Complex Joins +##### Alias 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 @@ -240,6 +241,7 @@ comments_with_replies = \ This will return the reply for the first comment. +##### CTE [Common Table Expressions (CTE)](https://en.wikipedia.org/wiki/Common_table_expressions#Common_table_expression) support via: Create a `CTE` @@ -262,6 +264,7 @@ users. # FROM users INNER JOIN cte_table ON users.id = cte_table.user_id ``` +#### Write SQL strings When your query is too complex for `Arel`, you can use `Arel::SqlLiteral`: ```ruby -- cgit v1.2.3