Returns referenced row.
public ref ( $key, $throughColumn = NULL ) : Nette\Database\Table\IRow | ||
return | Nette\Database\Table\IRow | or NULL if the row does not exist |
/** * @param \Nette\Database\Table\ActiveRow * @return \Nette\Security\Identity */ public function createIdentity(ActiveRow $user) { $data = $user->toArray(); unset($data['password']); $role = strtolower($user->ref('users_groups', 'group_id')->g_title); return new Identity($user->id, $role, $data); }
/** * Returns referenced row * * @param string $key * @param string $throughColumn * @return self|NULL if the row does not exist * @throws Nette\MemberAccessException if the relationship does not exist */ public function ref($key, $throughColumn = NULL) { $result = $this->activeRow->ref($key, $throughColumn); if ($result instanceof ActiveRow) { $hyperrow = $this->factory->createRow($result, $result->getTable()->getName()); return $hyperrow; } return NULL; }
public function getField(ActiveRow $row, $name) { if (isset($this->fields[$name])) { $column = $this->fields[$name]; return $row->{$column}; } if (isset($this->refs[$name])) { list($table, $column, $type) = $this->refs[$name]; $ref = $row->ref($table, $column); return $ref ? $this->manager->createEntity($type, $row) : NULL; } if (isset($this->related[$name])) { list($table, $column, $type) = $this->related[$name]; return $this->manager->createCollection($type, $row->related($table, $column)); } throw new Nette\InvalidArgumentException(); }
/** * Creates Addon entity from Nette\Database row. * * @todo Consider lazy loading for versions and tags. * * @param \Nette\Database\Table\ActiveRow * @param AddonVotes * @return Addon */ public static function fromActiveRow(ActiveRow $row, AddonVotes $addonVotes = NULL) { $addon = new static(); $addon->id = (int) $row->id; $addon->name = $row->name; $addon->composerVendor = $row->composerVendor; $addon->composerName = $row->composerName; $addon->userId = (int) $row->user->id; $addon->shortDescription = $row->shortDescription; $addon->description = $row->description; $addon->descriptionFormat = $row->descriptionFormat; $addon->defaultLicense = $row->defaultLicense; $addon->repository = $row->repository; $addon->repositoryHosting = $row->repositoryHosting; $addon->demo = $row->demo; $addon->updatedAt = $row->updatedAt ? DateTime::from($row->updatedAt) : NULL; $addon->deletedAt = $row->deletedAt; $addon->deletedBy = $row->ref('deletedBy'); $addon->type = $row->type; $addon->stars = $row->stars; foreach ($row->related('versions') as $versionRow) { $version = AddonVersion::fromActiveRow($versionRow); $version->addon = $addon; $addon->versions[$version->version] = $version; } foreach ($row->related('tags') as $tagRow) { $addon->tags[$tagRow->tag->id] = Tag::fromActiveRow($tagRow->tag); } foreach ($row->related('addons_resources') as $resourceRow) { $addon->resources[$resourceRow->type] = $resourceRow->resource; } if ($addonVotes) { $addon->votes = $addonVotes->calculatePopularity($row); } return $addon; }
/** * Appends referencing database table data to result set according to $this->deepListing * @param array $dest reference to data destination * @param \Nette\Database\Table\ActiveRow $row * @param array $map */ protected function getDeepData(array &$dest, ActiveRow $row, array $map) { foreach ($map as $key => $val) { if (is_array($val)) { if ($this->isValidId($dest[$key]) === FALSE) { continue; } $dest[$key] = $row->ref($key)->toArray(); $this->getDeepData($dest[$key], $row->ref($key), $val); } else { $oneToMany = strpos($val, '.'); if ($oneToMany) { $dest[substr($val, 0, $oneToMany)] = iterator_to_array($row->related($val), false); } else { $dest[$val] = $row->ref($val)->toArray(); } } } }
/** * @param string $key * @param string $throughColumn * @return Record|NULL */ public function ref($key, $throughColumn = NULL) { $this->checkRow(); $native = $this->row->ref($key, $throughColumn); return $native instanceof NActiveRow ? new static($native) : NULL; }