public function processQuerySet(QuerySet $qs, $alias, $autoGroup = true)
 {
     list($relatedModel, $joinTables) = $this->getJoin();
     foreach ($joinTables as $join) {
         $type = isset($join['type']) ? $join['type'] : 'LEFT OUTER JOIN';
         $newAlias = $qs->makeAliasKey($join['table']);
         $table = $join['table'] . ' ' . $newAlias;
         $from = $alias . '.' . $join['from'];
         $to = $newAlias . '.' . $join['to'];
         $on = $qs->quoteColumnName($from) . ' = ' . $qs->quoteColumnName($to);
         $qs->join($type, $table, $on);
         // Has many relations (we must work only with current model lines - exclude duplicates)
         //            if (isset($join['group']) && ($join['group']) && !$this->_chainedHasMany) {
         //                $this->_chainedHasMany = true;
         //            }
         $alias = $newAlias;
     }
     return [$relatedModel, $alias];
 }
 public function processQuerySet(QuerySet $qs, $alias, $autoGroup = true)
 {
     $grouped = false;
     list($relatedModel, $joinTables) = $this->getJoin();
     foreach ($joinTables as $join) {
         $type = isset($join['type']) ? $join['type'] : 'LEFT OUTER JOIN';
         $newAlias = $qs->makeAliasKey($join['table']);
         $table = $join['table'] . ' ' . $newAlias;
         $from = $alias . '.' . $qs->quoteColumnName($join['from']);
         $to = $newAlias . '.' . $qs->quoteColumnName($join['to']);
         $on = $qs->quoteColumnName($from) . ' = ' . $qs->quoteColumnName($to);
         $qs->join($type, $table, $on);
         // Has many relations (we must work only with current model lines - exclude duplicates)
         if ($grouped === false) {
             if ($autoGroup) {
                 $group = [];
                 if ($qs->getSchema() instanceof \Mindy\Query\Pgsql\Schema) {
                     $group[] = $newAlias . '.' . $qs->quoteColumnName($join['to']);
                 }
                 $group[] = $alias . '.' . $this->getModel()->getPkName();
                 $qs->group($group);
                 if ($qs->select) {
                     $qs->select = array_merge($qs->select, [$to]);
                 }
             }
             $qs->setChainedHasMany();
             $grouped = true;
         }
         $alias = $newAlias;
     }
     return [$relatedModel, $alias];
 }
 public function processQuerySet(QuerySet $qs, $alias, $autoGroup = true)
 {
     $grouped = false;
     list($relatedModel, $joinTables) = $this->getJoin();
     $throughAlias = null;
     foreach ($joinTables as $join) {
         $type = isset($join['type']) ? $join['type'] : 'LEFT OUTER JOIN';
         $newAlias = $qs->makeAliasKey($join['table']);
         $table = $join['table'] . ' ' . $newAlias;
         $from = $alias . '.' . $join['from'];
         $to = $newAlias . '.' . $join['to'];
         $on = $qs->quoteColumnName($from) . ' = ' . $qs->quoteColumnName($to);
         $qs->join($type, $table, $on);
         // Has many relations (we must work only with current model lines - exclude duplicates)
         if ($grouped === false) {
             if ($autoGroup) {
                 $qs->group([$this->getModel()->getPkName()]);
             }
             $grouped = true;
         }
         $alias = $newAlias;
         if (!$throughAlias) {
             $throughAlias = $alias;
         }
     }
     $through = null;
     if ($this->through) {
         $through = [new $this->through(), $throughAlias];
     }
     return [$through, [$relatedModel, $alias]];
 }