ZF2 multiple tables join in one model, get columns from join table

So here is my query:

public function fetchAd($adID){
    $row = $this->tableGateway->select(function(Select $select) use ($adID){
        $select->join('adDetails','adDetails.adID = ads.adID',array('*'),'inner');
        $select->where(array('ads.adID' => $adID));

    return $row->current();

So what I'm doing I'm querying the ad table and join the adDetails table in order for me to get the details for a certain AD, the problem is that the entity AD which belongs to the model that I'm doing the query, it doesn't have the columns names(variables) from the adDetails table; so it will only return the columns from the AD table, because the entity doesn't have those fields in the exchangeArray()

I have tried to extend the AD entity to use the AdDetails entity but it returns now to object array but with the fields as null, because it can;t populate them.

So, how should I do this, in order for me to have all the columns available in the model for the tables that will join?

I'm planning to join other tables as well.


Ok I solved the problem, the thing is that it will return an array, and it won't use the ORM style, but it does the job, for now relations are not supported in ZF2 like in ZF1;

    use Zend\Db\Sql\Sql,
    $sql = new Sql($this->tableGateway->getAdapter());
    $select = $sql->select();
          ->join('adDetails','adDetails.adID = ads.adID',array('*'),'inner');

    $where = new  Where();
    $where->equalTo('ads.adID', $adID) ;

    $statement = $sql->prepareStatementForSqlObject($select);
    $result = $statement->execute();

    return $result->current();

public function fetchJoin() 
    $select = new \Zend\Db\Sql\Select; 
    $select->from('tablea a'); 
    $select->join('tableb b', "b.id = a.b_id", array('field1'), 'left'); 
    // to display query string remove comment in next line
    //echo $select->getSqlString(); 
    $resultSet = $this->tableGateway->selectWith($select); 
    return $resultSet; 

Need Your Help

Ajax: Send PHP variable to JS without echo?

javascript php jquery html ajax

I'm fairly new to both PHP and Ajax, so this might seem trivial, although I couldn't seem to find a clear answer to this.

Reverse array function

c++ arrays function

so I have made a program that works in the following way.