Ash FrameworkAF
Ash Frameworkโ€ข3y agoโ€ข
27 replies
gvanders

Auto forms silently drops some associations

I ran into this while trying to use auto forms, grabbing values from the created
_join
form. There were no errors, but not all of the resource associations were present. Looks like here https://github.com/ash-project/ash_phoenix/blob/main/lib/ash_phoenix/form/auto.ex#L469 we use
Enum.find
, so we are only getting the first occurence of the association. I tried editing it to
Enum.filter
and changing the type from
:single
to :
list
. This made the associations properly appear in the form, but submitting it failed.

Got me wondering a few things. First, maybe I screwed up somewhere before ๐Ÿ˜… . Secondly for fixing it if it is a bug, it doesn't seem like we can know :single or :list beforehand , so would we need to use an anonymous function to resolve which similar to how data is resolved?
type: :single,
 data: &get_join(&1, &2, relationship),

Alternatively, is it possible to just make them all
:list
and handle the length = 1 case for single?
GitHub
https://hexdocs.pm/ash_phoenix. Contribute to ash-project/ash_phoenix development by creating an account on GitHub.
ash_phoenix/auto.ex at main ยท ash-project/ash_phoenix
Was this page helpful?