Skip to content

Instantly share code, notes, and snippets.

@mazz
Created April 23, 2019 00:53
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 mazz/010d733bbba4d64502f5653a61af1f85 to your computer and use it in GitHub Desktop.
Save mazz/010d733bbba4d64502f5653a61af1f85 to your computer and use it in GitHub Desktop.
line 18 and line 19 assignment does not impact outer scope established on line 1 and line 2
direction = :asc
sorting = :track_number
# direction = :desc
# sorting = :presented_at
media_category = Ecto.Query.from(playlist in Playlist,
where: playlist.uuid == ^playlist_uuid,
select: playlist.media_category)
|> Repo.one
|> IO.inspect
if media_category == :livestream ||
media_category == :motivation ||
media_category == :movie ||
media_category == :podcast ||
media_category == :testimony do
Logger.info("direction: #{direction} sorting: #{sorting}")
direction = :desc
sorting = :presented_at
else
direction = :asc
sorting = :track_number
end
Logger.info("direction: #{direction} sorting: #{sorting}")
query = from pl in Playlist,
# join: t in MusicTitle,
# join: c in Chapter,
join: mi in MediaItem,
# join: pt in PlaylistTitle,
where: pl.uuid == ^pid_uuid,
where: mi.playlist_id == pl.id,
# where: pl.id == pt.playlist_id,
where: mi.language_id == ^language_id,
order_by: [{^direction, field(mi, ^sorting)}],
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment