@@ -86,24 +86,6 @@ A Squeel keypath is essentially a more concise and readable alternative to a
8686deeply nested hash. For instance, in standard Active Record, you might join several
8787associations like this to perform a query:
8888
89- #### Rails 4+
90-
91- ``` ruby
92- Person .joins(:articles => {:comments => :person }).references(:all )
93- # => SELECT "people".* FROM "people"
94- # LEFT OUTER JOIN "articles" ON "articles"."person_id" = "people"."id"
95- # LEFT OUTER JOIN "comments" ON "comments"."article_id" = "articles"."id"
96- # LEFT OUTER JOIN "people" "people_comments" ON "people_comments"."id" = "comments"."person_id"
97- ```
98-
99- With a keypath, this would look like:
100-
101- ``` ruby
102- Person .joins{articles.comments.person}.references(:all )
103- ```
104-
105- #### Rails 3.x
106-
10789``` ruby
10890Person .joins(:articles => {:comments => :person })
10991# => SELECT "people".* FROM "people"
@@ -452,6 +434,43 @@ Seat.joins { [payment.outer, subquery.as('seat_order_items').on { id == seat_ord
452434# ) seat_order_items ON "seats"."id" = "seat_order_items"."orderable_id"
453435```
454436
437+ ### Includes
438+
439+ Includes works similarly with joins, it uses outer join defaultly. In Rails 4,
440+ you need to use ` references ` with ` includes ` together.
441+
442+ #### Rails 4+
443+
444+ ``` ruby
445+ Person .includes(:articles => {:comments => :person }).references(:all )
446+ # => SELECT "people".* FROM "people"
447+ # LEFT OUTER JOIN "articles" ON "articles"."person_id" = "people"."id"
448+ # LEFT OUTER JOIN "comments" ON "comments"."article_id" = "articles"."id"
449+ # LEFT OUTER JOIN "people" "people_comments" ON "people_comments"."id" = "comments"."person_id"
450+ ```
451+
452+ With a keypath, this would look like:
453+
454+ ``` ruby
455+ Person .includes{articles.comments.person}.references(:all )
456+ ```
457+
458+ #### Rails 3.x
459+
460+ ``` ruby
461+ Person .includes(:articles => {:comments => :person })
462+ # => SELECT "people".* FROM "people"
463+ # LEFT OUTER JOIN "articles" ON "articles"."person_id" = "people"."id"
464+ # LEFT OUTER JOIN "comments" ON "comments"."article_id" = "articles"."id"
465+ # LEFT OUTER JOIN "people" "people_comments" ON "people_comments"."id" = "comments"."person_id"
466+ ```
467+
468+ With a keypath, this would look like:
469+
470+ ``` ruby
471+ Person .includes{articles.comments.person}
472+ ```
473+
455474### Functions
456475
457476You can call SQL functions just like you would call a method in Ruby...
0 commit comments