Skip to content

Commit

Permalink
Give example combining eager_graph with where/order (Fixes #565)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremyevans committed Oct 17, 2012
1 parent acb361d commit 5f888fa
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions doc/advanced_associations.rdoc
Expand Up @@ -65,6 +65,18 @@ Remember, using +eager_graph+ is generally only necessary when you need to
filter/order based on columns in an associated table, it is recommended to
use +eager+ for eager loading if possible.

One advantage of using +eager_graph+ is that you can easily filter/order
on columns in an associated table on a per-query basis, using regular
Sequel dataset methods. For example, if you only want to retrieve artists
who have albums that start with A, and eager load just those albums,
ordered by the albums name, you can do:

albums = Artist.
eager_graph(:albums).
where(Sequel.like(:albums__name, 'A%')).
order(:albums__name).
all

For lazy loading (e.g. Model[1].association), the <tt>:dataset</tt> option can be used
to specify an arbitrary dataset (one that uses different keys, multiple keys,
joins to other tables, etc.).
Expand Down

0 comments on commit 5f888fa

Please sign in to comment.