Page 1 of 1

How to get all rows from related table using join

Posted: Sat Mar 18, 2017 6:12 pm
by dani34
I have two tables. First table contain offer details and second table contains offer collection of languages(collection can be selected in main offer form). I want to use query with "join" language table to get all of them in single query. How it's look like: Relation

Trying to get all of the offers I want to get all offer languages as one field.

Code: Select all

     array [
      'id' => string '11',
      'name' => string '134',
      'date' => string '01-12-2016',
      'languages' => array(all language value from related table)
     ]
Here is my query:

Code: Select all

        $select = $this->getDbTable()->select()
            ->setIntegrityCheck(false)
            ->from(array('o' => 'offers'), array('o.*'))
            ->joinLeft(array('ol' => 'offer_language'), 'ol(.)id_offer = o(.)id', array('ol.*'));

    $resultSet = $this->getDbTable()->fetchAll($select)
In that way if one offer has a three language then I get three same offer with different language field.

Zend Version: 1.11

Thanks for help.