Zend Framework

Zend_Db_Table_Select should include its own table in the FROM section

Details

  • Type: Bug Bug
  • Status: Resolved Resolved
  • Priority: Major Major
  • Resolution: Won't Fix
  • Affects Version/s: None
  • Fix Version/s: None
  • Component/s: Zend_Db_Table
  • Labels:
    None

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;
    }

Issue Links

Activity

Hide
julien PAULI added a comment -

Patch attached

Show
julien PAULI added a comment - Patch attached
Hide
Simon Mundy added a comment -

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.

Show
Simon Mundy added a comment - 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.
Hide
Tim Fisken added a comment -

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

Show
Tim Fisken added a comment - Although this bug is marked as resolved, it actually is the cause of a number of other bugs listed with Zend_Db_Table_Select.
Hide
Tomáš Fejfar added a comment -

For me, the expected usage is:

// 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 !

Show
Tomáš Fejfar added a comment - For me, the expected usage is:
// 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 !
Hide
David Muir added a comment -

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

$bugs = new Bugs();
$bugs->select()->join('Table2', 'Bugs.id = Table2.bug_id')->where('whatever = 1');

becomes

SELECT `Bugs`.*
FROM `Table2`
INNER JOIN `Bugs`
WHERE whatever = 1

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

Would be good if this issue were reopened and fixed.

Show
David Muir added a comment - 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
$bugs = new Bugs();
$bugs->select()->join('Table2', 'Bugs.id = Table2.bug_id')->where('whatever = 1');
becomes
SELECT `Bugs`.*
FROM `Table2`
INNER JOIN `Bugs`
WHERE whatever = 1
To fix it you have to specify a from clause explicitly. Would be good if this issue were reopened and fixed.
Hide
Ralph Schindler added a comment -

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

Show
Ralph Schindler added a comment - 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
Hide
julien PAULI added a comment -

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 :

$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".

Show
julien PAULI added a comment - 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 :
$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".
Hide
Ralph Schindler added a comment -

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

Show
Ralph Schindler added a comment - 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
Hide
julien PAULI added a comment -

true and right

Show
julien PAULI added a comment - true and right

People

Vote (0)
Watch (5)

Dates

  • Created:
    Updated:
    Resolved: