@@ -3523,6 +3523,8 @@ defmodule AshSql.Expr do
35233523 :bracket
35243524 end
35253525
3526+ declared_field = type && field_constraints ( constraints , next )
3527+
35263528 { next , type , constraints } =
35273529 cond do
35283530 type && Ash.Type . embedded_type? ( type ) ->
@@ -3559,6 +3561,10 @@ defmodule AshSql.Expr do
35593561 { name , type , constraints }
35603562 end
35613563
3564+ declared_field ->
3565+ { field_type , field_constraints } = declared_field
3566+ { next , field_type , field_constraints }
3567+
35623568 true ->
35633569 { next , nil , nil }
35643570 end
@@ -3602,6 +3608,20 @@ defmodule AshSql.Expr do
36023608 end
36033609 end
36043610
3611+ # The type a `fields` constraint declares for `next`, if it declares one.
3612+ defp field_constraints ( constraints , next ) do
3613+ with true <- Keyword . keyword? ( constraints || [ ] ) ,
3614+ fields when is_list ( fields ) <- constraints [ :fields ] ,
3615+ { _name , config } <-
3616+ Enum . find ( fields , fn { name , _config } ->
3617+ if is_binary ( next ) , do: to_string ( name ) == next , else: name == next
3618+ end ) do
3619+ { config [ :type ] , config [ :constraints ] || [ ] }
3620+ else
3621+ _ -> nil
3622+ end
3623+ end
3624+
36053625 defp list_requires_encoding? ( value ) do
36063626 ! Enum . empty? ( value ) &&
36073627 Enum . any? ( value , fn value ->
0 commit comments