
I have had to recently work on complex queries which involved performing aggregration etc which made it little difficult to stick to the regular data set mapping to a model, as the regular doSelect would try and do a hydrate and since the new columns (say defined by count or avg) wont match with the standard columns in the model, you will get offset errors. One way out is to break out of it and use doSelectRS/doSelectStmt that will allow you get your dataset as an array.
Thought I would also mention the difference between the three as its easy to refer back to it later.
With Propel, you need to understand the differences between the three sorts of select:
doSelectdoSelectRS/doSelectStmt(for Propel 1.2/1.3 respectively)doSelectJoin
- The MyTablePeer::doSelect method will hydrate the MyTable objects. It assumes that it’s getting all the fields of the object, that they’re the first fields returned, and that they’re in the same order as they appear in the schema file. It will ignore any additional fields in the result set. In other words, doSelect doesn’t play well with
addSelectColumn,clearSelectColumn, oraddJoin. - The
MyTablePeer::doSelectRSorMyTablePeer::doSelectStmtreturn the raw result set (for Propel 1.2) or executed PDO statement (for Propel 1.3). These methods don’t do any hydration. The 1.3doSelectStmtis actually very useful if you need specialized results, because of the power of the PDO fetch and fetchAll methods. I suggest reading the PDO docs for this method. -
The
MyTablePeer::doSelectJoin*methods are the only Propel methods that will hydrate more than one table automatically, as far as I know. And they’ll only hydrate two tables (at least in Propel 1.2; I’m not 100% sure about the new features in Propel 1.3).
Bottom line: If you’re joining tables, your choices are to either use the doSelectJoin* methods, if there’s one that meets your needs, or deal with the unhydrated results.
Reference: http://www.symfony-project.org/forum/index.php/m/63944/#msg_63944
