Skip to content

Instantly share code, notes, and snippets.

@ytnobody
Created December 2, 2019 06:12
Show Gist options
  • Select an option

  • Save ytnobody/abac5a34fa533e9185208e82c0dfb039 to your computer and use it in GitHub Desktop.

Select an option

Save ytnobody/abac5a34fa533e9185208e82c0dfb039 to your computer and use it in GitHub Desktop.

Revisions

  1. ytnobody created this gist Dec 2, 2019.
    5 changes: 5 additions & 0 deletions ecto-select-count-groupby.exs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,5 @@
    from(bookshelf in Bookshelf,
    join: book in Book, on bookshelf.id == book.bookshelf_id,
    group_by: bookshelf.id,
    select: %{bookshelf_id: bookshelf.id, books_count: count(book.id)}
    ) |> Repo.all()