Skip to content

Instantly share code, notes, and snippets.

@benvp
Created July 10, 2017 15:47
Show Gist options
  • Save benvp/64c1facb7ac72c7f5f3729b1ae709dae to your computer and use it in GitHub Desktop.
Save benvp/64c1facb7ac72c7f5f3729b1ae709dae to your computer and use it in GitHub Desktop.
LearningElixir.tv - Ecto Part 2
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
Copy link

def reload(schema) do
  Repo.get(schema.__struct__, schema.id)
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment