python-statemachine icon indicating copy to clipboard operation
python-statemachine copied to clipboard

Examples with multiple models ie from 1:1 to x:1 on Order and OrderControl

Open patrickwolf opened this issue 6 months ago • 1 comments

Great example on Order and OrderControl. https://python-statemachine.readthedocs.io/en/latest/auto_examples/order_control_rich_model_machine.html

Would find it helpful to see how python-statemachine supports users with 2+ orders. ie does it have to be 1:1 Order & OrderControl or are there patterns for x:1 where there are many models and a single state machine controller that can work with and advance the state on multiple models.

I imagine many run into this and would be great to see a best practices example!

Thanks!

patrickwolf avatar Jun 22 '25 08:06 patrickwolf

Hi @patrickwolf, how are you?

Could you elaborate a bit more on your use case? In this context, I’m considering changing the Order model to something like an OrderCollection model, which would encapsulate the complexity of managing multiple Order instances within the OrderControl machine. The OrderCollection could have its own set of validations—for example, allowing only orders in the same state—and it would propagate state changes to all internal order instances when a new state is entered.

That said, I’m just exploring possibilities. With a concrete example, we could dive deeper.

fgmacedo avatar Aug 02 '25 17:08 fgmacedo