ZF-1335: Provide table-specific SELECT queries with select() method
Description
Original message by Michael Depetrillo:
Hello
I was wondering if it made sense to add a select($cols) helper method to Zend_Db_Table that would return an instance of Zend_Db_Select.
Example:
<?php
Model_Lead extends Zend_Db_Table_Abstract { $_name = 'leads_table'; }
$lead = new Model_Lead();
$select = $lead->select(new Zend_Db_Expr('COUNT(*)')->where('status = ?', 'pending');
echo $select; // select COUNT(*) from leads_table
?>
This would be very helpful in centralizing tables names through models.
Comments
Posted by michael depetrillo (klassicd) on 2007-05-01T12:18:08.000+0000
There was a typo in my original message. The example above should return "select count(*) from leads_table where status = ?".
Posted by Bill Karwin (bkarwin) on 2007-05-01T13:46:00.000+0000
A workaround that exists right now is the following:
This issue is related to ZF-836, which requests a feature of a table method fetchCount().
We aren't going to address this use case in ZF 1.0. We would like to provide a solution later, but I'm going to postpone this issue for now.
Posted by Simon Mundy (peptolab) on 2008-01-26T17:45:01.000+0000
With the new Zend_Db_Table enhancements you can now perform
Does that satisfy the requirements of this request? If so I'll mark it as complete.
Posted by Wil Sinclair (wil) on 2008-12-19T11:36:45.000+0000
Michael, can you please verify that Simon's solution is adequate?