MVC pattern usual practice for saving more than one model in a transaction

211 views Asked by At

I want to save two models in a transaction but it will be used on more than one view.

Should I put that transaction in one of those models? Or should I somehow reuse the controller action?

What is the best practice for MVC pattern in this case?

note: My view is consisted of more than one model.

1

There are 1 answers

0
Asgaroth On

That depends, if your business logic, tells you that every time you save model A, model B should be updated/created as well. then put the transaction in your model, so that no matter where you call it (controller , CLI) it will remain true for your logic.

If on the other hand, this transaction is something that only matters to the current user request, then put that in your controller.

At this point the views are irrelevant, you can have any number of models in your view. it has nothing to do with your business logic.