Exemple #1
0
 protected function buildJoins($val, $inner = FALSE)
 {
     $driver = $this->selection->getConnection()->getSupplementalDriver();
     $reflection = $this->selection->getConnection()->getDatabaseReflection();
     $joins = array();
     preg_match_all('~\\b([a-z][\\w.:]*[.:])([a-z]\\w*|\\*)(\\s+IS\\b|\\s*<=>)?~i', $val, $matches);
     foreach ($matches[1] as $names) {
         $parent = $this->selection->getName();
         if ($names !== "{$parent}.") {
             // case-sensitive
             preg_match_all('~\\b([a-z][\\w]*|\\*)([.:])~i', $names, $matches, PREG_SET_ORDER);
             foreach ($matches as $match) {
                 list(, $name, $delimiter) = $match;
                 if ($delimiter === ':') {
                     list($table, $primary) = $reflection->getHasManyReference($parent, $name);
                     $column = $reflection->getPrimary($parent);
                 } else {
                     list($table, $column) = $reflection->getBelongsToReference($parent, $name);
                     $primary = $reflection->getPrimary($table);
                 }
                 $joins[$name] = ' ' . (!isset($joins[$name]) && $inner && !isset($match[3]) ? 'INNER' : 'LEFT') . ' JOIN ' . $driver->delimite($table) . ($table !== $name ? ' AS ' . $driver->delimite($name) : '') . ' ON ' . $driver->delimite($parent) . '.' . $driver->delimite($column) . ' = ' . $driver->delimite($name) . '.' . $driver->delimite($primary);
                 $parent = $name;
             }
         }
     }
     return $joins;
 }
Exemple #2
0
 /**
  * @internal
  */
 public function access($key, $cache = TRUE)
 {
     if ($this->table->getConnection()->getCache() && !isset($this->modified[$key]) && $this->table->access($key, $cache)) {
         $id = isset($this->data[$this->table->getPrimary()]) ? $this->data[$this->table->getPrimary()] : $this->data;
         $this->data = $this->table[$id]->data;
     }
 }