Ash Form Questions
Are there any gotchas with AshPhoenix.Form.create_for and child resources inside an inputs_for? I'm getting an unkown error and I'm not sure what's going wrong because the example in the documentation seems to indicate that the child object in a has_many relationship just gets created?
My guess is that there's something I need to opt into configuration wise in the resource to ahve this work?
24 Replies
What is
forms
in your call to Forms.for_create
?its a component prop
let me split out the code blocks again
Mostly I mean what is the value of that variable
the value of the
forms
option determines what child forms are availableoh
answers: [
type: :list,
resource: PollAnswer,
create_action: :create
]
child list of a resource at the many end of a one to many relationship
gotcha, and whats the error that you're getting?
š¤
Which wasn't very helpful.
yeah that looks less than ideal š
Would posting the resources help?
potentially...
lets try a couple things first
step 1.
mix hex.outdated
to check for any ash packages out of date
and then mix deps.update ash ash_phoenix ...
for whichever packages could use an upgradeYeah, let me make sure nothing is out of date.
I see that quite a few are a couple of minor versions behind.
thats me releasing new features/fixes š
Okay, so I updated all my packages that I could and reset my database and the issue persists.
š
š¤
so one thing I'm noticing is that there is no call to
manage_relationship
in your poll resource action
Shouldn't cause this issue
but without that, these child forms won't actually do anything
You pasted this in:
is PollAnswer
properly aliased?yes
poll_form is the component that handles rendering and the configuration is handled.
try this
instead of
submit!
use submit
which returns {:ok, poll}
and {:error, new_form}
are you seeing any warning level logs about missed errors?
AshPhoenix.Form
doesn't dump all error messages into the form for safety reasons. Only specific messages. And by default it logs a warning about errors it didn't displaysubmit_errors: [poll_id: {"is required", []}]
hmm
Let me see if a call to manage_relationships resolves this.
And no, no warning logs anywhere.
I had to go in and actually look at the errors that were in the form.
ah, yeah okay
I see the issue
here is what you likely actually want
and then for
forms
you want forms: [auto?: true]
auto?: true
will set appropriate context on the answer
forms that they shouldn't require poll_id
yet (because its not been created š )
and it will derive the forms
option from the manage_relationship
call in the actionokay
that was way easier than I would've thought.
thank you.
š„³