In a server application where exists models like "Articles", "Jobs", "Workers" and

For example in a server side app where there are those models:

  • Products
  • Jobs
  • Workers

And there is an action like start job which does the following things:

  • Products: the job's product's quantity requested is increased
  • Jobs: the job is inserted
  • Workers: the job's worker is set unavailable and it's saved a reference to the current job

Now My question is: where should I put the logic described above?

  • Should I have a controller named "jobs/start" which calls the method on the model "job.start(args...)". Inside this model method it calls "product.increaseRequestedQuantity(args...)" and "worker.setBusy()"

  • Should I have a controller named "jobs/start" which calls "job.start(args...)" then "product.increaseRequestedQuantity(args...)" and "worker.setBusy()"

I don't really know which is a best practice, in the first the model is aware of the other models, but the logic is central. In the second the models are not aware of each others directly but the logic is more distributed. Also having a method named "start" on the job, one would assume that it would start a job at the application level (which means it changes the product and worker model) but affects at model level (means that only changes the job model, without changing the product and worker model).

What are your opinion about the matter and this separation of concerns?

This applies for people that used Rails, even if I'm not talking about Rails in particular (my own framework based on services+models in node.js, where a service is like a controller in Rails), or any other MC framework, (note that I don't care about the view because the service must only export the data. The view is only on the client side which requests data).

I've read about Should rails models be concerned with other models for the sake of skinny controllers? but I would like something more deep explained if possible, also with book/links references at this exact topic.

Thanks for your time at reading my question (:

0

There are 0 best solutions below