Exemplo n.º 1
0
 protected function parseFinder(Sql $sql, Finder $finder, $alias, &$aliases, &$conditions)
 {
     $entity = $finder->getName();
     $parent = $finder->getParentName();
     $next = $finder->getNextName();
     $parentAlias = $parent ? $aliases[$parent] : null;
     $aliases[$entity] = $alias;
     $parsedConditions = $this->parseConditions($conditions, $finder, $alias);
     if (!empty($parsedConditions)) {
         $conditions[] = $parsedConditions;
     }
     if (is_null($parentAlias)) {
         return $sql->from($entity);
     } elseif ($finder->isRequired()) {
         $sql->innerJoin($entity);
     } else {
         $sql->leftJoin($entity);
     }
     if ($alias !== $entity) {
         $sql->as($alias);
     }
     $aliasedPk = "{$alias}." . $this->findPrimaryKey($entity);
     $aliasedParentPk = "{$parentAlias}." . $this->findPrimaryKey($parent);
     if ($entity === "{$parent}_{$next}") {
         return $sql->on(array("{$alias}.{$parent}_id" => $aliasedParentPk));
     } else {
         return $sql->on(array("{$parentAlias}.{$entity}_id" => $aliasedPk));
     }
 }
Exemplo n.º 2
0
 protected function parseCollection(Sql $sql, Collection $collection, $alias, &$aliases, &$conditions)
 {
     $entity = $collection->getName();
     $parent = $collection->getParentName();
     $next = $collection->getNextName();
     $parentAlias = $parent ? $aliases[$parent] : null;
     $aliases[$entity] = $alias;
     $parsedConditions = $this->parseConditions($conditions, $collection, $alias);
     if (!empty($parsedConditions)) {
         $conditions[] = $parsedConditions;
     }
     if (is_null($parentAlias)) {
         return $sql->from($entity);
     } elseif ($collection->isRequired()) {
         $sql->innerJoin($entity);
     } else {
         $sql->leftJoin($entity);
     }
     if ($alias !== $entity) {
         $sql->as($alias);
     }
     $aliasedPk = $alias . '.' . $this->getStyle()->primaryFromTable($entity);
     $aliasedParentPk = $parentAlias . '.' . $this->getStyle()->primaryFromTable($parent);
     if ($entity === $this->getStyle()->manyFromLeftRight($parent, $next) || $entity === $this->getStyle()->manyFromLeftRight($next, $parent)) {
         return $sql->on(array($alias . '.' . $this->getStyle()->foreignFromTable($parent) => $aliasedParentPk));
     } else {
         return $sql->on(array($parentAlias . '.' . $this->getStyle()->foreignFromTable($entity) => $aliasedPk));
     }
 }
Exemplo n.º 3
0
 protected function parseMixins(Sql $sql, Collection $collection, $entity)
 {
     if ($this->mixable($collection)) {
         foreach ($this->getMixins($collection) as $mix => $spec) {
             $sql->innerJoin($mix);
             $sql->as("{$entity}_mix{$mix}");
         }
     }
 }