Skip to content

Instantly share code, notes, and snippets.

@hykw
Created July 29, 2016 07:18
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 hykw/06507f42d2782f99b34e4f5da5c7317f to your computer and use it in GitHub Desktop.
Save hykw/06507f42d2782f99b34e4f5da5c7317f to your computer and use it in GitHub Desktop.
ecto, preloadでソート
child_query = from c in Child, order_by: c.code
query = from p in Parent,
where p.id == ^id,
order_by: p.date,
preload: [child: ^child_query]
case Repo.all(query) do
nil -> {:not_found}
record -> {:ok, record}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment