I have a query:
RetestCategory
|> select([rc], %{id: rc.id, name: rc.name})
|> order_by([rc], rc.id)
|> Repo.all
|> Enum.map(fn(rc) -> ["#{rc.name}": rc.id] end)
|> List.flatten
But is there a way to avoid the Enum.map
part by doing something like this?
RetestCategory
|> select([rc], %{"#{rc.name}": rc.id})
|> order_by([rc], rc.id)
|> Repo.all
|> List.flatten