But of course I have much more complex queries going on. In the past, if the query involves joining 1 or more table I have created a separate function for it. The problem is that I now have a whole lot of these functions. They are cluttering my models and don't even do anything object-oriented so they kinda seam like a waste of space to have there.
I am now trying to minimize these, if not remove them completly. I realize that I could just write all these queries in the Controllers and use the model to format the data for how the view needs it but this seams to just be moving the problem from one to the other, not actually solving the problem. Its quite difficult to read through the code when there are these really big queries everywhere.
So that brings us to my question, how do I handle these really large queries? I want to do something like I am doing for the simple queries but just have no ideas. This is how I would do a simple query to pull, for example, all the news items:
Code: Select all
$this->view->news = Singleton::getObject('News')
->setCacheTitle('newsLoggedInFrontPage'.Singleton::getObject('Languages')->fetchLanguageCode())
->setCacheTags(array('news'))
->fetchEntries(
array(
'headline',
'url_headline',
'short_story',
'posted_time'
),
array(
'is_front_page' => '1',
'active' => '1',
'fk_language_code' => Singleton::getObject('Languages')->fetchLanguageCode()
),
4, 'id DESC'
)
->formatForUser()->fetchData();One idea I had was to extend my main models with another "queries" model, so I would have like Models_News and then Models_Queries_News and the Models_Queries_News would be just a class that was a function container that housed the large queries, the same way as now but quite a bit more out of the way, a place I would hardly have to go to and debug and whatnot. But I am not sure if that is really the right way to go about it.
What do you guys do in these cases? How have you handled it? What roles do your contollers and models play and how do you extend them to add functionality?