Hello.
Is there a possibility to check if the given Ecto Query has a specific expression?
For example, if query q has already expression order_by filled in
Take a look at: Ecto.Query — Ecto v3.8.3
You can access the order_bys
like this:
iex(1)> query = from u in "users", order_by: [u.name], select: [u.name, u.age]
#Ecto.Query<from u0 in "users", order_by: [asc: u0.name],
select: [u0.name, u0.age]>
iex(2)> query.order_bys
[
%Ecto.Query.QueryExpr{
expr: [asc: {{:., [], [{:&, [], [0]}, :name]}, [], []}],
file: "iex",
line: 12,
params: []
}
]
1 Like
Always keep in mind that most parts of the query internals are implementation details and might change at any time.