ZF-2546: Zend_Db_Table_Select should include its own table in the FROM section
Description
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 :
public function setTable(Zend_Db_Table_Abstract $table)
{
$this->_adapter = $table->getAdapter();
$this->_info = $table->info();
return $this;
}
patch could be :
public function setTable(Zend_Db_Table_Abstract $table)
{
$this->_adapter = $table->getAdapter();
$this->_info = $table->info();
$this->from($this->_info[Zend_Db_Table_Abstract::NAME]);
return $this;
}
Comments
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 (tomas.fejfar@gmail.com) on 2008-11-19T10:50:45.000+0000
For me, the expected usage is:
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
becomes
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.
-ralph
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 :
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:
$table->select(Zend_Db_Table::WITH_FROM_PART)->setItegrityCheck()....
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 ;-)