sto avendo alcuni problemi di tradurre questa query da utilizzare di ZF Zend_Db_Select
:Tradurre una query per utilizzare Zend_Db_Select
SELECT b.id, b.title, b.description
FROM memberships AS m
JOIN blogs AS b ON b.id = m.blog_id
WHERE m.user_id = ?
ORDER BY m.created
LIMIT 0, 30
(questa query funziona e restituisce i risultati)
Memberships
è una tabella di collegamento tra il blogs
e users
. È un semplice affare | id | blog_id | user_id |
.
Ecco quello che ho finora:
// $table = Zend_Db_Table instance, $id = a user id
$select = $table->select()
->from(array('m' => 'memberships'), array('b.id', 'b.title', 'b.description'))
->join(array('b' => 'blogs'), 'b.id = m.blog_id')
->where('m.user_id = ?', (int) $id)
->order('m.created DESC')
->limit(0, 30);
Questa è la (strano (per me)) errore che sto ricevendo:
#0: Select query cannot join with another table
è verificato nella riga 211 del
D:\...\library\Zend\Db\Table\Select.php
.
Grazie per il vostro aiuto.
Questo ha funzionato come volevo a. Tuttavia sembra che restituisca i risultati come una matrice, piuttosto che come un oggetto? Non è un problema, mi chiedo solo perché. – Ross
Non dovrebbe, in realtà. Come si esegue l'istruzione select? $ select-> query() dovrebbe restituire un PDO_Statement o un Zend_Db_Statement. –