iex(18)> fields = [:id]
[:id]
iex(19)> fields_map = %{id: :job_id}
%{id: :job_id}
iex(20)> query = from p in Qber.V1.JobModel, where: p.id == 1, select: map(p, ^fields)
#Ecto.Query<from j in Qber.V1.JobModel, where: j.id == 1, select: map(j, [:id])>
I want to select my fields dynamically with AS names on the basis of params I got(which may have some joins as this app is going to have heavy admin dashboard queries). So I need dynamic solution. is there a way I can pass a map instead of list dynamically to map function and ecto will send me the selected result with custom names I passed in map.
Instead of
[%{id: 1}]
I want the result to be
[%{job_id: 1}]
dynamically.
Some more context
My question is related to this question actually
select-fields-dynamically and I have also posted a question here. As I am joining many tables with same keys and I either want these keys to be alias so that these can be unique or map them inside their table name for uniqueness. Thanks