Pass create changeset or inputs from it to Flow?
In my resource I have these two create actions:
As you can see, the
place_offer
action will call my flow Flows.MakeOffer
. Inside that flow, I have this step:
This step calls the create
action and creates the offer
.
Now, is this the best/correct way to do it?
What I see as probably wrong is that I'm already receiving a changeset in the place_offer
create action, but I'm just getting the inputs from it and ignoring the rest because the create
action will generate a new changeset later.
I was thinking that maybe I should pass the changeset to the Flow, but then I'm not sure how I would pass it to the create
action.
What is your suggestion?12 Replies
I think in your case you can run the flow in a
before_action
hook
and then let the action actually submit itselfI'm gonna be honest, I'm not sure I got what you meant 😅
Errors in a
before_action
step will abort the transactionSo, the idea is that with this is that I can remove the
create
action and the step that calls it from my flow because the place_offer
action will create the offer?yep!
I see, in that case, I don't need to pass all the attributes, only the ones needed to the other steps of the flow
And, in case adding the offer should be done after some specific step, then the way I did is correct?
Yeah, although there are also
after_action
hooksFor example, I have step 1, 2, 3 inside a transaction in my step, and step 2 is the step that should add the offer
But to use the after_action in this case I would need to have 2 Flows correct? One for after and one for before
yes, you would 🙂
Although I don't tend to use flows just for things that wrap an action (i.e setup + side effects)
But thats a perfectly valid way to use them
Got it!
And, just to confirm, even if I use this, the transaction would be the same both in that action and inside the flow when using before_action and after_action correct?
I thought that was the whole point of flows 😅
What do you use for that? a bunch of before/after_action calls in a
change
call inside the create action?Yes
If you run the flow in a transaction already, the whole flow will be in that transaction.
I use flows for like…long series of events with complex ordering of operations.
Or that do “fanning out” to operate on many elements
Ah, I see, that makes sense, I will try to rewrite what I have now using
change