Awan
Awan

Reputation: 18600

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', 'address.id = user.address_id', array( 'city' => 'address.city' ) ); then it shows only user table data.

How to get Both table's data??

Thanks

Upvotes: 1

Views: 1519

Answers (2)

Tjorriemorrie
Tjorriemorrie

Reputation: 17302

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'))
);

Upvotes: 3

Distdev
Distdev

Reputation: 2312

try to use

$select = $table->select(Zend_Db_Table::SELECT_WITH_FROM_PART);

Upvotes: 1

Related Questions