ZF-2546: Zend_Db_Table_Select should include its own table in the FROM section

Issue Type: Bug Created: 2008-02-01T08:38:25.000+0000 Last Updated: 2009-08-26T09:19:20.000+0000 Status: Resolved Fix version(s): Reporter: julien PAULI (doctorrock83) Assignee: julien PAULI (doctorrock83) Tags: - Zend_Db_Table

Related issues: - ZF-3239

Attachments: - Zend_Db_Table_Select-ZF2546.patch


Zend_Db_Table_Select should include its own table name in the FROM section, as it's its goal :) Actually it does not add the actual table to the from clause.

actual code :

<pre class="highlight">
    public function setTable(Zend_Db_Table_Abstract $table)
        $this->_adapter = $table->getAdapter();
        $this->_info    = $table->info();
        return $this;

patch could be :

<pre class="highlight">
    public function setTable(Zend_Db_Table_Abstract $table)
        $this->_adapter = $table->getAdapter();
        $this->_info    = $table->info();
        return $this;


Posted by julien PAULI (doctorrock83) on 2008-02-08T17:54:34.000+0000

Patch attached

Posted by Simon Mundy (peptolab) on 2008-02-16T20:57:09.000+0000

Hi Julien

I removed it specifically from there as I wanted the ability for the 'FROM' to be applied either by the developer during query creation, or 'just-in-time' before the query is executed. This is handy, as it means that the select object doesn't need to be tied down with a one-to-one relationship with the parent table.

Posted by Tim Fisken (timf) on 2008-08-22T16:51:39.000+0000

Although this bug is marked as resolved, it actually is the cause of a number of other bugs listed with Zend_Db_Table_Select.

Posted by Tomáš Fejfar ( on 2008-11-19T10:50:45.000+0000

For me, the expected usage is:

<pre class="highlight"> 
// Bugs
$bugs = new Bugs();
$bugs->select()->where('something = ?',$id); 
// I want to manipulate the table data - that's why I use the class !
$bugs->getAdapter()->select()->from('Other_Table')->where('whatever = 1'); 
// I don't wnat the "bugs" included? I'll use the adapter's method

The present situation is confusing. I create the class because I want to save time and typing when manipulating THIS BUG TABLE, not because I want it to perform various DB tasks with it !

Posted by David Muir (dmuir) on 2009-03-05T23:00:57.000+0000

Agree with Tomas. Using Zend_Db_Table_Select implies you are wanting to select from the given table. If you don't want that, then you should be using Zend_Db_Select instead.

Simon, can you give a reasonable use case where you'd use Zend_Db_Table_Select instead of Zend_Db_Select to select from a table other than the table from which the select came from? This is especially frustrating as the current implementation flips the order of the from and join

<pre class="highlight">
$bugs = new Bugs();
$bugs->select()->join('Table2', ' = Table2.bug_id')->where('whatever = 1');


<pre class="highlight">
SELECT `Bugs`.*
FROM `Table2`
WHERE whatever = 1

To fix it you have to specify a from clause explicitly.

Would be good if this issue were reopened and fixed.

Posted by Ralph Schindler (ralph) on 2009-08-25T17:15:57.000+0000

Since 1.9 there has been a feature in place that allowed select() to be called on a table with that will load the from part into the object.

Please see here, and the api doc here

I think it might fix this problem.


Posted by julien PAULI (doctorrock83) on 2009-08-26T00:28:52.000+0000

It does, except that you have to explicitly choose it ($table->select(true)), which makes the API look strange.

And you have to do that if you want joins to work :

<pre class="highlight">
$table->select()->setIntegrityCheck(false)->join('other_table', "$this->_name.mycol = other_table.itscol", "some-col");

won't work and will complain about "columns mycol not in $this->_name table".

Posted by Ralph Schindler (ralph) on 2009-08-26T07:05:56.000+0000

True, but its not something we can change pre 2.0. Also, to make it more readable, one might consider using:


I'd suggest adding these notes to the Zend_Db 2.0 pages in ZFDEV wiki

Posted by julien PAULI (doctorrock83) on 2009-08-26T09:19:18.000+0000

true and right ;-)

Have you found an issue?

See the Overview section for more details.


© 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.