Created
July 10, 2017 15:47
-
-
Save benvp/64c1facb7ac72c7f5f3729b1ae709dae to your computer and use it in GitHub Desktop.
LearningElixir.tv - Ecto Part 2
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 reload(item) do | |
%struct{} = item | |
pk = struct.__schema__(:primary_key) |> List.first | |
%{^pk => id} = item | |
get(struct, id) | |
end | |
def max(queryable, fieldName) do | |
query = from x in queryable, | |
select: max(field(x, ^fieldName)) | |
all(query) | |
end |
danielberkompas
commented
Jul 14, 2017
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment