Skip to content

Instantly share code, notes, and snippets.

@nietaki
Created October 15, 2019 21:36
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 nietaki/c1000f2422062c3ce92706b2cd320610 to your computer and use it in GitHub Desktop.
Save nietaki/c1000f2422062c3ce92706b2cd320610 to your computer and use it in GitHub Desktop.
simpler_query = from(c in Comment, where: c.user_id == ^charlie_id)
non_preloaded = Repo.all(simpler_query)
assert Enum.all?(non_preloaded, fn c -> c.post == nil end)
comments_by_charlie = Repo.preload(non_preloaded, [:post])
refute Enum.any?(comments_by_charlie, fn c -> c.post == nil end)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment