Help to join two tables in Zend
I have two table. user
and address
. I am joining them like this in zend:
$table = new Model_User_DbTable();
$select = $table->select();
$select->setIntegrityCheck( false );
$select->join( 'address', 'address.id = user.address_id', array( 'city' => 'address.city' ) );
$row = $table->fetchAll( $select );
return $row;
But above query is returning all addresses from address but not data from user table. When I remove $select->join( 'address', 'addres开发者_StackOverflow中文版s.id = user.address_id', array( 'city' => 'address.city' ) );
then it shows only user table data.
How to get Both table's data??
Thanks
Untested:
$table = new Model_User_DbTable();
$resultSet = $table->fetchAll($table->select()
->setIntegrityCheck(false)
->from(array('u'=>'user'))
->join(array('a'=>'address'), 'u.address_id = a.id', array('city'=>'address_city'))
);
try to use
$select = $table->select(Zend_Db_Table::SELECT_WITH_FROM_PART);
精彩评论