Hi,

I'm getting an error with a query, my question is: can i chain joins?

My first join is to the primary table, but my second join is to the table joined to the primary table. This is the query:

|$query=  $this->getDbTable()->select()
            ->from(array('ca'  =>  'contracts_allotment'),
                    array('id',
                        'contracts_rooms_id'  =>  new  
Zend_Db_Expr("CONCAT(room_type_desc, '-', room_characteristics_desc)")
                        ))
            ->join(array('cr'  =>  'contracts_rooms'),
                    'ca.contract_rooms_id = cr.id',
                    array())
            ->join(array('rt'  =>  'room_types'),
                    'cr.room_id = rt.id',
                    array('room_type_desc'))
            ->join(array('rc'  =>  'room_characteristics'),
                    'cr.char_id = rc.id',
                    array('room_characteristics_desc'))
            ->where('contract_id = ?',  $contractId);

        var_dump($this->getDbTable()->fetchAll($query));die;|

I'm getting:

   Select query cannot join with another table"

The error comes from |Zend/Db/Table/Select::assemble()|

Here you have some inside assemble():

|    // Check each column to ensure it only references the primary table
   if  ($column)  {
       if  (!isset($from[$table])  ||  $from[$table]['tableName']  !=  
$primary)  {
           var_dump($from[$table]['tableName'],  $primary);die;
           require_once'Zend/Db/Table/Select/Exception.php';
           throw  new  Zend_Db_Table_Select_Exception('Select query cannot join 
with another table');
       }
   }|

The |var_dump()| prints:

   string(10) "room_types" string(19) "contracts_allotment"

Any idea?

Javi

Reply via email to