Continued Confusion in the Zend DB Class
I’m still questioning how I should best use the Zend Framework’s database model classes.
The data structure of the current application I’m building is not very complicated: there are 8 tables of between 2 and 11 fields each, and some of the tables are simple parent tables that define user types or status types.
To simplify, three of the tables that do the heaviest lifting do so in a hierarchy like a tree: a user table has a one-to-many relationship with a submissions table, which, in turn, has a one-to-many relationship with a recommendations table.
I extended the Zend_Db_Table_Abstract to model each table (as well described in the documentation). That was easy; I like that.
And I like the ease of calling rows from the tables – for example:
$users = new Users();
$user = $users->fetchAll(”email=’$values[’email’]'”)->current();
And making and saving changes:
$user->firstname = ‘Brian’;
$user->save();
And, too, getting a set of dependent rows from another table is easy as well:
$userSubmissions = $user->findDependentRowset(’Submissions’);
But what if I want to get the dependent rows from recommendations for each of the rows returned in $userSubmissions?
I could loop through $userSubmissions and call findDependentRowset() for each, but once I have that data into the script, how do I maintain the relationships for each submission to its recommendations? I would receive an instance of Zend_Db_Table_Rowset holding the recommendations for each submission but the submissions themselves are row objects in a rowset object – are the recommendation rows bound in any way to their submission row?
If I have the findDependentRowset() calls in the controller action methods, how do I transfer what the controller knows, so to speak, to the view? Should the view itself make the calls for each submission and convert each piece of data to its proper presentation immediately?
Is the question irrelevant because I’ve misunderstood the MVC pattern?
The last few days I’ve been trying to think about how I might extend the Zend_Db_Table_Abstract, Zend_Db_Table_Rowset, and Zend_Db_Table_Row classes for my specific situation. Like, for example, altering the findDependentRowset() method for the User class (which extends Zend_Db_Table_Abstract) to save its results within the row, but will that alter the performance of ActiveRecord functions, like save()?
I’m not sure. I’ll come up with a solution – that won’t be the problem. But I do wish there were more good tutorials for Zend that could provide guides toward good practice.
No Responses
Add your response
Respond to “Continued Confusion in the Zend DB Class”