ZF-5830: Zend_Db_Table_Select doesn't allow use of $select->columns('..')
Description
Zend_Db_Table_Select doesn't allow use of $select->columns('..')
code fragment: $tbl = new Category_Table(); $select = $tbl->select()->columns('id');
Results: Zend_Db_Select_Exception: No table has been specified for the FROM clause in /usr/share/php/Zend-1.7.5/Db/Select.php on line 224
Expected: Zend_Db_Table_Select should already have a table when created from a Zend_Db_Table_Abstract.
Bug?: Zend_Db_Table_Select's from clause isn't set till assemble()
Comments
Posted by julien PAULI (doctorrock83) on 2009-02-20T05:29:03.000+0000
Agreed.
I already told Zend (ralph probably) that a Zend_Db_Table_Select should be given it's own table in the from clause, just after creating it. It's not logic to have a Zend_Db_Table_Select entirely empty at creation, it should at least contains its own table as its first from clause.
See :
Posted by Michael Rehbein (tech13) on 2009-02-26T10:27:28.000+0000
Turns out just adding the from in the setTable doesn't act as expected.
$select = $tbl->select()->columns('id'); would still include an all columns in the select.
'select
table.* ,table.idfromtable'Attached is a patch I used to fix the bug for me.
short version: Added a different version of the columns method for the class that includes the 'from' on demand. If a column not from the primary table is requested, it will throw an error. Seemed logical since the assemble for Zend_Db_Table_Select would throw for any columns not in the primary table.
Posted by Jurrien Stutterheim (norm2782) on 2009-03-11T20:29:47.000+0000
This issue is already known as ZF-3239. It's a tricky one and hard solve without BC issues. A real patch probably won't be available until ZF 2.0, where we can break the BC a bit. Although I would love to be proven wrong in this case ;)
Posted by Ralph Schindler (ralph) on 2009-08-25T17:15:30.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 Michael Rehbein (tech13) on 2010-02-22T11:02:44.000+0000
Was fixed as of 1.9. Marking issue closed.
Posted by Enrico Hofmann (ehofmann) on 2012-04-25T12:59:20.000+0000
I got this error, today on Version 1.10.6.
Posted by Nico Mebes (nicomebes) on 2012-06-08T12:34:50.000+0000
Got the same error today. Version 1.11.5
Posted by Crispen Smith (crispen) on 2012-07-21T15:28:16.000+0000
Also using Version 1.11.5, replicated the issue using this code:
and:
All other pulls from the same pattern work fine, but when I try to specify just the index_images column I get error message:
Message: No table has been specified for the FROM clause
Luckily enough, it's a lightweight table and I was just doing minor performance tuning, but it would be nice if this could be resolved.