Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Give example combining eager_graph with where/order (Fixes #565)

  • Loading branch information...
commit 5f888fa9e2f7de8f950adabf6991d05861407a5b 1 parent acb361d
Jeremy Evans authored October 17, 2012

Showing 1 changed file with 12 additions and 0 deletions. Show diff stats Hide diff stats

  1. 12  doc/advanced_associations.rdoc
12  doc/advanced_associations.rdoc
Source Rendered
@@ -65,6 +65,18 @@ Remember, using +eager_graph+ is generally only necessary when you need to
65 65
 filter/order based on columns in an associated table, it is recommended to
66 66
 use +eager+ for eager loading if possible.
67 67
 
  68
+One advantage of using +eager_graph+ is that you can easily filter/order
  69
+on columns in an associated table on a per-query basis, using regular
  70
+Sequel dataset methods.  For example, if you only want to retrieve artists
  71
+who have albums that start with A, and eager load just those albums,
  72
+ordered by the albums name, you can do:
  73
+
  74
+  albums = Artist.
  75
+    eager_graph(:albums).
  76
+    where(Sequel.like(:albums__name, 'A%')).
  77
+    order(:albums__name).
  78
+    all
  79
+
68 80
 For lazy loading (e.g. Model[1].association), the <tt>:dataset</tt> option can be used
69 81
 to specify an arbitrary dataset (one that uses different keys, multiple keys,
70 82
 joins to other tables, etc.).

0 notes on commit 5f888fa

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