Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions lib/expr.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3523,6 +3523,8 @@ defmodule AshSql.Expr do
:bracket
end

declared_field = type && field_constraints(constraints, next)

{next, type, constraints} =
cond do
type && Ash.Type.embedded_type?(type) ->
Expand Down Expand Up @@ -3559,6 +3561,10 @@ defmodule AshSql.Expr do
{name, type, constraints}
end

declared_field ->
{field_type, field_constraints} = declared_field
{next, field_type, field_constraints}

true ->
{next, nil, nil}
end
Expand Down Expand Up @@ -3602,6 +3608,20 @@ defmodule AshSql.Expr do
end
end

# The type a `fields` constraint declares for `next`, if it declares one.
defp field_constraints(constraints, next) do
with true <- Keyword.keyword?(constraints || []),
fields when is_list(fields) <- constraints[:fields],
{_name, config} <-
Enum.find(fields, fn {name, _config} ->
if is_binary(next), do: to_string(name) == next, else: name == next
end) do
{config[:type], config[:constraints] || []}
else
_ -> nil
end
end

defp list_requires_encoding?(value) do
!Enum.empty?(value) &&
Enum.any?(value, fn value ->
Expand Down
Loading