Answer the question
In order to leave comments, you need to log in
How to correctly implement the saving of related models?
Hello.
I have two models, an order and steps to complete this order
order
orderId
name
...
status
step
stepId
title
...
status
that is, one order can have many steps, for example, draw, cut, pack ...
If we pack in a step changes to ready, then, accordingly, for all subsequent steps, the status also changes to ready ...
and the order itself is not ready for dispatch ...
The problem is that I don’t know how to implement it better, I don’t want to prescribe it all in the controller, maybe someone tell me the best way to do it? I thought to change the statuses for steps through afterSaveEvent, but I doubt it :(
Answer the question
In order to leave comments, you need to log in
all this should be implemented not in the controller, but in the order model. It manages all related data and changes statuses etc. There can be many implementations, for example, through events like afterSave
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question