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];
 }