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]; }
/** * Пересчитываем дерево после удаления моделей через * $modelClass::objects()->filter(['pk__in' => $data])->delete(); * @return int */ public function delete() { $deleted = parent::delete(); $this->prepareProblemLftRgt(); return $deleted; }
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]]; }
/** * @param \Mindy\Orm\QuerySet|\Mindy\Orm\Manager $qs * @return mixed */ public function search($qs) { $fields = $this->getSearchFields(); if (isset($this->params['search']) && !empty($fields)) { $filters = []; foreach ($fields as $field) { $lookup = 'contains'; $field_name = $field; if (strpos($field, '=') === 0) { $field_name = substr($field, 1); $lookup = 'exact'; } $filters[] = [implode('__', [$field_name, $lookup]) => $this->params['search']]; } $qs->filter([new OrQ($filters)]); } return $qs; }