New to Ash so let me know if there is a better way to accomplish what I’m attempting.
I have an AshPhoenix.Form created with AshPhoenix.Form.for_create. Naturally, when I submit this form it creates a new resource in my Postgres database and returns {:ok, %MyNewResource{}}.
Is there a way I can get %MyNewResource{} before I submit the form? The reason I want it is because that Ash.Resource has calculations on it that I rely on in order to make an external API call when the form is submitted.
So my desired flow is:
- User hits submit
- I make a call to the Google Calendar API, passing in the result of a calculated field
- I merge the resulting google_calendar_event_id into params
- I call AshPhoenix.Form.submit with the merged params
I can’t figure out a good way to get the result of a calculated field in step 2 without having my resource, and manually creating the resource from the form params sounds like the wrong way to do it.