get node models

@param $class
@param integer $relation_id
@return \Illuminate\Database\Eloquent\Collection
490626
private function getNodeModels($class, $relation_id)
    {
        if ($this->request->id === '0') {
            return is_null($relation_id)
                ? $class::all()->toHierarchy()
                : $class::where('parent_id',$relation_id)->get()->toHierarchy();
        }

        return $class::findOrFail($this->request->id)->descendants()->limitDepth(1)->get();
    }
885031
public function getChild ($relationIdentifier, $id, $childId)
		{
			$relation = $this->getRelation($relationIdentifier);

			$query = $this->database->createQuery()->whereEqual(
				$relation->getRelatedTable() . '.' . $this->database->primaryKey($relation->getRelatedTable()),
				$childId
			);

			return $this->getChildren($relationIdentifier, $id, $query)->fetchRow();
		}
1250856
public function getRelations ()
	{
		
		// Create new database tool

		$db	= new Db;
		
		$relations	= $db->getRelations ($this->get ('database'), $this->get ('table'));
		$namespace	= $this->getRootNamespace ();

		// Loop through constraints

		foreach ($relations as $constraint)
		{
			
			// If the attribute exists
			
			if (isset ($this->attributeCache[$constraint['attribute']]))
			{
				
				// Add relationship
				
				$this->attributeCache[$constraint['attribute']]['relation']	= $this->parser->convertToClassName ($constraint['table'], $namespace);
				
			}

		}
		
	}
864635
public function find($class, $id)
    {
        if (!isset($id)) {
            return;
        }

        if (null === $class) {
            return $this->dm->find(null, $id);
        }

        return $this->dm->getRepository($class)->find($id);
    }
597379
public function fetchAllObj(string $class = null): array
    {
        if ($class == null && $this->modelClass !== null) {
            return parent::fetchAllObj($this->modelClass);
        } else {
            return parent::fetchAllObj($class);
        }
    }
211045
public function getMany($relatedClass)
    {
        $table = ucfirst($relatedClass::getTable());
        $column = "shared{$table}List";
        return static::wrap($this->bean->$column, $relatedClass);
    }
926709
public function getChildren ($relationIdentifier, $id, $inputQuery = null)
		{
			$relation = $this->getRelation($relationIdentifier);
			$query    = $this->database->createQuery();

			if ($relation instanceof OneToMany) {
				$query->whereEqual($relation->getRelatedTable() . '.' . $relation->getKey(), $id);

			} else if ($relation instanceof ManyToMany) {
				$query->addField($relation->getRelationalTable() . '.*')
					->leftJoinEqual(
						$relation->getRelationalTable(),
						$relation->getRelationalTable() . '.' .$relation->getRelatedKey(),
						$relation->getRelatedTable() . '.' . $relation->getRelatedKey()
					)
					->whereEqual($relation->getRelationalTable() . '.' . $relation->getKey(), $id);

			} else {
				throw new RelationException('Invalid relation type `' . gettype($relation) . '`');
			}

			$query->composeWith($inputQuery);

			return $relation->getRelatedTableObject()->getRows($query);
		}
944954
public Object find(Class entityClass, Object rowId) {
        EntityMetadata entityMetadata = KunderaMetadataManager.getEntityMetadata(kunderaMetadata, entityClass);
        List<String> relationNames = entityMetadata.getRelationNames();
        return find(entityClass, entityMetadata, rowId, relationNames);
    }
604450
public function getRelationClass($relationName)
    {
        // Parse many_many
        $manyManyComponent = $this->getSchema()->manyManyComponent(static::class, $relationName);
        if ($manyManyComponent) {
            return $manyManyComponent['childClass'];
        }

        // Go through all relationship configuration fields.
        $config = $this->config();
        $candidates = array_merge(
            ($relations = $config->get('has_one')) ? $relations : array(),
            ($relations = $config->get('has_many')) ? $relations : array(),
            ($relations = $config->get('belongs_to')) ? $relations : array()
        );

        if (isset($candidates[$relationName])) {
            $remoteClass = $candidates[$relationName];

            // If dot notation is present, extract just the first part that contains the class.
            if (($fieldPos = strpos($remoteClass, '.')) !== false) {
                return substr($remoteClass, 0, $fieldPos);
            }

            // Otherwise just return the class
            return $remoteClass;
        }

        return null;
    }
786137
protected function getRelationMethodSection(array $relationships, $type = CmsModel::RELATION_TYPE_MODEL)
    {
        $replace = '';

        $relatedClassName = $this->context->getModelNamespaceForSpecialModel($type);

        foreach ($relationships as $name => $relationship) {

            $relationParameters       = '';
            $relationMethodParameters = '';

            if ($relationKey = array_get($relationship, 'key')) {
                $relationParameters = ", '{$relationKey}'";
            }

            if (    array_get($relationship, 'translated')
                &&  $type !== CmsModel::RELATION_TYPE_MODEL
                &&  config('pxlcms.generator.models.allow_locale_override_on_translated_model_relation')
            ) {
                $relationMethodParameters = '$locale = null';

                // skip parameters not entered, pass on the optional locale key
                $relationParameters = (substr_count($relationParameters, ',') ? null : ', null')
                                    . ', null'
                                    . ', $locale';
            }

            $replace .= $this->tab() . "public function {$name}({$relationMethodParameters})\n"
                      . $this->tab() . "{\n"
                      . $this->tab(2) . "return \$this->{$relationship['type']}({$relatedClassName}::class"
                      . $relationParameters
                      . ");\n"
                      . $this->tab() . "}\n"
                      . "\n";


            if ($type == CmsModel::RELATION_TYPE_IMAGE) {
                // since images require special attention for resize enrichment,
                // add an accessor method that will take care of it (through some magic)
                $replace .= $this->tab() . "public function get" . studly_case($name) . "Attribute()\n"
                          . $this->tab() . "{\n"
                          . $this->tab(2) . "return \$this->getImagesWithResizes();\n"
                          . $this->tab() . "}\n"
                          . "\n";
            }

        }

        return $replace;
    }
785617
public function getParent ($relationIdentifier, $id, $inputQuery = null)
		{
			$relation = $this->getRelation($relationIdentifier);

			if (! $relation) {
				throw new RelationException('Invalid relation `' . $relationIdentifier);
			}

			if ($relation instanceof ManyToOne && $relation instanceof OneToOne) {
				throw new RelationException('Invalid relation type `' . $relation['type'] . '`');
			}

			$row = $this->getRow($id);

			$query = $this->database->createQuery()
				->whereEqual($relation->getKey(), $row[$relation->getRelatedKey()])
				->composeWith($inputQuery);

			return $relation->getRelatedTableObject()->getRows($query)->fetchRow();
		}
761040
public static function where($column, $relation, $value)
    {
        $self = self::instance();
        $key = $self->_keyName;
        $data = \Query::from($self->_table)->select($key)->where($column, $relation, $value)->get();
        $rows = [];

        if (!is_null($data)) {
            foreach ($data as $item) {
                $rows[] = self::instance($item->$key);
            }
        }

        return $rows;
    }
1097661
public function getRelation($respondentId, $relationId)
    {
        $filter = array(
            'grr_id_respondent' => $respondentId,        // Just a safeguard to make sure we get only relations for this patient
            'grr_id'            => $relationId
        );

        $data = $this->loadFirst($filter);

        if (!$data) {
            $data = array();
        }

        $relationObject = $this->loader->getInstance('Model_RespondentRelationInstance', $this, $data);

        return $relationObject;
    }
280140
public function getModel($class, $id)
	{
		if ($id instanceof $class) {
			return $id;
		} elseif (ctype_digit(strval($id))) { // целое число в виде числа или текстовой строки
			return $class::findOrFail($id);
		} else {
			//TODO: Использовать свое исключение
			throw new \Exception("Can't get model.", 1);
		}
	}
876924
protected function getRelationCondition($relation, $value)
    {
        /** @var \yii\db\ActiveRecord $relationClass */
        $relationClass = $relation->modelClass;
        if ($relation->via !== null) {
            /* @var $viaRelation \yii\db\ActiveQuery */
            $viaRelation = is_array($relation->via) ? $relation->via[1] : $relation->via;
            /** @var \yii\db\ActiveRecord $viaClass */
            $viaClass = $viaRelation->modelClass;
            $subquery = (new Query)
                ->select(array_map(function ($key) {
                    return 'j.' . $key;
                }, array_keys($viaRelation->link)))
                ->from(['t' => $relationClass::tableName()])
                ->innerJoin(['j' => $viaClass::tableName()], implode(' AND ', array_map(function ($leftKey, $rightKey) {
                    return 't.' . $leftKey .' = j.' . $rightKey;
                }, array_keys($relation->link), array_values($relation->link))))
                ->where(['IN', array_map(function ($key) {
                    return 't.' . $key;
                }, $relationClass::primaryKey()), $value]);
            $linkKeys = array_values($viaRelation->link);
        } else {
            $subquery = (new Query)
                ->select(array_keys($relation->link))
                ->from(['t' => $relationClass::tableName()])
                ->where(['IN', array_map(function ($key) {
                    return 't.' . $key;
                }, $relationClass::primaryKey()), $value]);
            $linkKeys = array_values($relation->link);
        }
        return ['IN', array_map(function ($key) {
            return 't.' . $key;
        }, $linkKeys), $subquery];
    }
67385
private function _loadOrCreateRelationModel($data, $fks, $modelClass, $relationName)
    {

        /** @var BaseActiveRecord $relationModel */
        $relationModel = null;
        if (!empty($fks)) {
            $relationModel = $modelClass::findOne($fks);
        }
        if (!($relationModel instanceof BaseActiveRecord) && !empty($data)) {
            $relationModel = new $modelClass;
        }
        // If a custom scenario is set, apply it here to correctly be able to set the model attributes
        if (array_key_exists($relationName, $this->_relationsScenario)) {
            $relationModel->setScenario($this->_relationsScenario[$relationName]);
        }
        if (($relationModel instanceof BaseActiveRecord) && is_array($data)) {
            $relationModel->setAttributes($data);
            if ($relationModel->hasMethod('loadRelations')) {
                $relationModel->loadRelations($data);
            }

        }
        return $relationModel;
    }
1264192
public function getRelations()
    {
        $relations = $columns = [];

        foreach ($this->builder->fields() as $field) {
            $columns[] = $field->column();
        }

        foreach (array_flatten($columns) as $column) {
            if (str_contains($column, '.')) {
                list($relation) = explode('.', $column);

                if (method_exists($this->model, $relation) &&
                    $this->model->$relation() instanceof Relation
                ) {
                    $relations[] = $relation;
                }
            } elseif (method_exists($this->model, $column) &&
                !method_exists(Model::class, $column)
            ) {
                $relations[] = $column;
            }
        }

        return array_unique($relations);
    }