2009年7月16日星期四

Re: [fw-db] Bug or Feature? Joining tables with Zend_Db_Table

Hello,

OK, I did find a value piece of information.
The Join is only built if there exists a call of the FROM method in the select object!

$select-> (...)
          ->from('Bugs');


BUT:

Object I do build the select on is: Class Bugs for table bugs.
So I do expect to have a result like

SELECT bugs.* [, account.*] FROM bugs [INNER] join accounts on [CONDITION] WHERE ...

What I do get is always:

SELECT accounts, bugs.* FROM accounts [INNER] join bugs on [CONDITION] WHERE ...

In my opinion, this is similar to a bug, because the priority and order of the tables is confused.

If I have an object on table bugs, and I build the select based on this object:
$table = new Bugs(); $select = $table->select  then I do expect to have the Table bugs in the from clause an nowhere else (except if i join with bugs ...) But it does appear in the JOIN clause!  any suggestion, did i miss something?    
Mathias Grub schrieb:
Hello,

I'm trying to build a join with Zend_Db_Table.
Because it does not work at all, i tried the example from the doc, but it does also not work as expected:

$table = new Bugs();  // retrieve with from part set, important when joining $select = $table->select(Zend_Db_Table::SELECT_WITH_FROM_PART); $select->setIntegrityCheck(false)        ->where('bug_status = ?', 'NEW')        ->join('accounts', 'accounts.account_name = bugs.reported_by')        ->where('accounts.account_name = ?', 'Bob');  //$rows = $table->fetchAll($select);   $select->__toString()  gives me a query for starting like SELECT accounts.* FROM accounts (NO JOIN !?)  What I did expect, was to get a query for table Bugs: SELECT bugs.* FROM bugs INNER JOIN accounts ON ...  Do joins in Zend_Db_Table work? 

没有评论: