Issue Details (XML | Word | Printable)

Key: ZF-5830
Type: Bug Bug
Status: Closed Closed
Resolution: Duplicate
Priority: N/A N/A
Assignee: Ralph Schindler
Reporter: Michael Rehbein
Votes: 1
Watchers: 3
Operations

If you were logged in you would be able to see more operations.
Google issue summary
Zend Framework

Zend_Db_Table_Select doesn't allow use of $select->columns('..')

Created: 18/Feb/09 12:14 PM   Updated: 22/Feb/10 11:02 AM   Resolved: 22/Feb/10 11:02 AM
Component/s: Zend_Db_Table
Affects Version/s: 1.7.5
Fix Version/s: None

Time Tracking:
Not Specified

File Attachments: 1. Text File Table_Select.patch (3 kB)

Issue Links:
Duplicate


 Description  « Hide

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()



julien PAULI added a comment - 20/Feb/09 05:29 AM

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 :

// that's not logic
$table->fetchall($table->select()->from($table, array('my', 'cols')));
// that seems more logic
$table->fetchall($table->select()->columns(array('my', 'cols')));

Michael Rehbein added a comment - 26/Feb/09 10:27 AM

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`.`id` from `table`'

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.


Jurrien Stutterheim added a comment - 11/Mar/09 08:29 PM

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


Ralph Schindler added a comment - 25/Aug/09 05:15 PM

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


Michael Rehbein added a comment - 22/Feb/10 11:02 AM

Was fixed as of 1.9. Marking issue closed.