/** * Will join named relations * @param dmDoctrineQuery $query * @param array $aliases * @param boolean $with18n */ public function joinRelations($query, array $aliases, $withI18n = false) { $rootAlias = $query->getRootAlias(); foreach ($aliases as $alias) { if (!($relation = $this->getRelationHolder()->get($alias))) { throw new dmException(sprintf('%s is not a valid alias for the table %s', $alias, $this->getComponentName())); } if ($relation->getAlias() === 'Translation') { $query->withI18n(); } elseif ($relation->getClass() === 'DmMedia') { $mediaJoinAlias = dmString::lcfirst($relation->getAlias()); $query->leftJoin(sprintf('%s.%s %s', $rootAlias, $relation->getAlias(), $mediaJoinAlias))->leftJoin(sprintf('%s.%s %s', $mediaJoinAlias, 'Folder', $mediaJoinAlias . 'Folder')); } else { $joinAlias = dmString::lcfirst($relation->getAlias()); $query->leftJoin(sprintf('%s.%s %s', $rootAlias, $relation->getAlias(), $joinAlias)); if ($withI18n && $relation->getTable()->hasI18n()) { $joinTranslationAlias = $joinAlias . 'Translation'; $query->leftJoin($joinAlias . '.Translation ' . $joinTranslationAlias . ' ON ' . $joinAlias . '.id = ' . $joinTranslationAlias . '.id AND ' . $joinTranslationAlias . '.lang = ?', myDoctrineRecord::getDefaultCulture()); } } } return $this; }
public function getAdminListQuery(dmDoctrineQuery $q) { return $q->leftJoin($q->getRootAlias() . '.Areas a')->leftJoin('a.Zones z')->leftJoin('z.Widgets w')->orderBy('a.type DESC'); }