Reputation: 721
I have a conceptual question, what is the best way to gather information from various models and treat them in different ways in order to return an array with the requested data, without using a "god" method?
I'll summarize the example I'm trying:
View "Payroll" is characterized by a html table that shows information of an employee, for example: base salary, every discount of the month (from the Payments table) as well as commissions from another table, so in Controller I just do $this->set($employee_info, $this->Employee->getInfo());
This method is responsible for gathering information from models that are not even related to him in some way (e.g.: Configuration Model) and at the end it returns the array required, the question is: what the best way to separate these responsibilities?
Upvotes: 1
Views: 166
Reputation: 25698
This method is responsible for gathering information from models that are not even related to him in some way
You won't get around to call several models in this case in what you call a "god" method. The only way to get around that is to associate the data.
I would create three methods, one that fetches the data from all models, one that creates the data structure you want from that data and one that calls the two others and returns the data. I don't see a better way to separate that without having the data associated.
Upvotes: 1