Issues

ZF-1335: Provide table-specific SELECT queries with select() method

Issue Type: New Feature Created: 2007-05-01T08:21:51.000+0000 Last Updated: 2008-12-19T13:58:05.000+0000 Status: Resolved Fix version(s): - 1.5.0 (17/Mar/08)

Reporter: Darby Felton (darby) Assignee: Simon Mundy (peptolab) Tags: - Zend_Db_Table

Related issues: - ZF-836

Attachments:

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:

<pre class="highlight">
<?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:

<pre class="highlight">
$lead = new Model_Lead();
$select = $lead->getAdapter()->select();
$select->from($lead->info()['name'], 'COUNT(*)');
$select->where('status = ?', 'pending');

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

<pre class="highlight">
$lead = new Model_Lead();
$select = $lead->select();
$select->from($lead, 'COUNT(*)')->where('status = ?', 'pending');

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?

Have you found an issue?

See the Overview section for more details.

Copyright

© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.

Contacts