Skip to content

Instantly share code, notes, and snippets.

@paulcsmith
Created March 19, 2015 21:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paulcsmith/2615513d0602915fb98b to your computer and use it in GitHub Desktop.
Save paulcsmith/2615513d0602915fb98b to your computer and use it in GitHub Desktop.
Complex Ecto Queries with joins and deep preload
def with_sorted_comments do
from a in Announcement,
left_join: c in assoc(a, :comments),
left_join: u in assoc(c, :user),
order_by: [asc: c.inserted_at],
preload: [:interests, :user, comments: {c, user: u}]
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment