简体   繁体   中英

zend framework 2, paginator with join

I'm writing with zend framework 2, but I have a problem when I use pagination with join. I've this function:

            if ($paginated) {       
                $select = new \Zend\Db\Sql\Select ();
                $select->from ( 'cliente' );
                $select->columns ( array ('*'), false );
                $select->join ( 'privato', "cliente.idCliente = privato.idCliente", array ('*'), 'left' );
                $select->join ( 'azienda', "cliente.idCliente = azienda.idCliente", array ('*'), 'left' );

                $resultSetPrototype = new ResultSet ();
                $resultSetPrototype->setArrayObjectPrototype ( new Cliente () );
                $paginatorAdapter = new DbSelect ( 
                        $select, 
                        $this->tableGateway->getAdapter ()); 
                        $resultSetPrototype );
                //$paginatorAdapter = $this->tableGateway->selectWith ( $select );
                $paginator = new Paginator ( $paginatorAdapter );
                return $paginator;
            }

            $select = new \Zend\Db\Sql\Select ();
            $select->from ( 'cliente' );
            $select->columns ( array ('*') );
            $select->join ( 'privato', "cliente.idCliente = privato.idCliente", array ('*'), 'left' );
            $select->join ( 'azienda', "cliente.idCliente = azienda.idCliente", array ('*'), 'left' );

            $resultSet = $this->tableGateway->selectWith ( $select );
            return $resultSet;

the code outside the if statement works correctly, the internal code no. Gives me this message:

            Statement could not be executed (42S21 - 1060 - Duplicate column name 'idCliente')

where is the error? thank you very much

$select->columns ( array ('idCliente1'=>'idCliente'), false ); 

是因为您必须提供一个别名,或者在联接上,您可以通过定义所需的所有列名称来忽略idCliente:

        $select->join ( 'azienda', "cliente.idCliente = azienda.idCliente", array ('column1','column2','etc..'), 'left' );

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM