public function getChildren() { /** @var Record|TTree $this */ if (is_null($this->_children)) { $this->_children = RecordSet::createFromForeign($this, get_class($this)); } return $this->_children; }
/** * @param $className * @return mixed * @throws RecordsManException */ public function loadForeign($className) { $foreignClass = Helper::qualifyClassName($className); if (isset($this->_foreign[$foreignClass])) { return $this->_foreign[$foreignClass]; } $relationType = $this->getRelationTypeWith($foreignClass); $relationParams = $this->getRelationParamsWith($foreignClass); /** @var Record|string $foreignClass */ switch ($relationType) { case self::RELATION_BELONGS: $fKeyValue = $this->get($relationParams['foreignKey']); $this->_foreign[$foreignClass] = $fKeyValue ? $foreignClass::load($fKeyValue) : null; break; case self::RELATION_MANY: $this->_foreign[$foreignClass] = RecordSet::createFromForeign($this, $foreignClass); break; } return $this->_foreign[$foreignClass]; }