public function access($key, $delete = FALSE) { if ($this->table->connection->cache && $this->table->access($key, $delete)) { $this->data = $this->table[$this->data[$this->table->primary]]->data; } }
protected function execute() { if ($this->rows !== NULL) { return; } $referencing = & $this->refTable->referencing[$this->getSql()]; if ($referencing === NULL) { $limit = $this->limit; $rows = count($this->refTable->rows); if ($this->limit && $rows > 1) { $this->limit = NULL; } parent::execute(); $this->limit = $limit; $referencing = array(); $offset = array(); foreach ($this->rows as $key => $row) { $ref = & $referencing[$row[$this->column]]; $skip = & $offset[$row[$this->column]]; if ($limit === NULL || $rows <= 1 || (count($ref) < $limit && $skip >= $this->offset)) { $ref[$key] = $row; } else { unset($this->rows[$key]); } $skip++; unset($ref, $skip); } } $this->data = & $referencing[$this->active]; if ($this->data === NULL) { $this->data = array(); } }
/** * Returns referenced row. * @param string * @return TableRow or NULL if the row does not exist */ public function getReferencedTable($name, & $column = NULL) { $column = $this->connection->databaseReflection->getReferencedColumn($name, $this->name); $referenced = & $this->referenced[$name]; if ($referenced === NULL) { $keys = array(); foreach ($this->rows as $row) { if ($row[$column] !== NULL) { $keys[$row[$column]] = NULL; } } if ($keys) { $table = $this->connection->databaseReflection->getReferencedTable($name, $this->name); $referenced = new TableSelection($table, $this->connection); $referenced->where($table . '.' . $this->getPrimary($table), array_keys($keys)); } else { $referenced = array(); } } return $referenced; }