Skip to content

Instantly share code, notes, and snippets.

@mazz mazz/query.ex
Created Apr 23, 2019

Embed
What would you like to do?
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
You can’t perform that action at this time.