Hey, Quick question for the design gurus of large web apps using ZF (or similar framework): In situations where an app has many special data requirements and non-trivial queries, as well as the wish to optimize queries as much as possible, it may make sense to use raw queries rather than things like Zend_Db_Select, etc. How do you keep growing and complex, raw queries maintainable? Example:
In a "Post" model, you may have: # get all active posts public function getAll() { $qryPosts = "SELECT id, content, date FROM posts WHERE active = 1"; return $this->getAdapter()->query($qryPosts)->fetchAll(); } # check if a post is valid (exists in the database and is active) public function isValid($post_id = 0) { $qryIsValid = $this->getAdapter()->quoteInto("SELECT id FROM posts WHERE id = ? AND active = 1", (int)$post_id, 'INTEGER'); return $this->getAdapter()->query($qryIsValid)->fetchOne(); } You see the issues: (1) it's important to have a method like isValid() if somewhere in form validation you want to see if the post a user is trying to edit actually exists, and you want this to be a simple query for the id and not have the database return unneeded columns, but (2) as more methods are written that touch the "posts" table, they all have to include "WHERE active = 1" and any other business requirements associated with posts. How are developers using Zend Framework dealing with this and preserving maintainability? Is it ad-hoc/homebrew or do more elegant solutions exist? ____________________________________________________________________________________ Be a better Heartthrob. Get better relationship answers from someone who knows. Yahoo! Answers - Check it out. http://answers.yahoo.com/dir/?link=list&sid=396545433