Last active
March 9, 2019 20:44
-
-
Save sergey-chechaev/aaf46b967c39bcc461b16bc7392a23fd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def list_user_posts(user_id) do | |
Post | |
|> distinct(true) | |
|> where([p], p.user_id == ^user_id) | |
|> join(:left, [p], d in assoc(p, :user)) | |
|> join(:left, [_p, d], co in assoc(d, :country)) | |
|> join(:left, [_p, d], ci in assoc(d, :city)) | |
|> join(:left, [p, _d], ph in assoc(p, :post_photos)) | |
|> preload([_p, d, co, ci, ph], user: {d, country: co, city: ci}, post_photos: ph) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment