Find and return the child using parent id, parent type and child id.

@param integer $parentId
@param string $parentType
@param integer $childId
@return ModelHierarchy
768689
public static function findChild( $parentId, $parentType, $childId ) {

		return self::find()->where( 'parentId=:pid AND parentType=:type AND childId=:cid', [ ':pid' => $parentId, ':type' => $parentType, ':cid' => $childId ] )->one();
	}
738476
public static function findByParentId( $parentId, $config = [] ) {

		$limit 		= $config['limit'] ?? null;
		return self::find()->where( 'parentId=:id', [ ':id' => $parentId ] )->limit($limit)->all();
	}
267389
public function findChildrenTreeByParentId($parent_id)
    {
        $qb = $this->createQueryBuilder();

        $qb = $this->alterQueryBuilderWithParentRoot($qb, $parent_id);

        $qb->orderBy($qb->getRootAliases()[0] . '.lft', 'ASC');

        return $this->getResultFromQueryBuilder($qb);
    }
473035
protected function buildAncestorQuery($childId)
    {
        // We don't use Eloquent here because of endless subquery nesting
        $grammar = $this->select()->getGrammar();

        $table = $this->model->getTable();
        $idKey = $this->model->getKeyName();
        $idQueryColumn = $grammar->wrap("$table.$idKey");

        $childQuery = $this->select(["$table.$this->parentIdKey"])
                           ->where("$table.$idKey", $childId);

        $last = $childQuery;
        $queries = [];

        for ($i=1; $i <= $this->_maxDepth; $i++) {

            $queries[] = $this->buildOuterAncestorQuery($i, $last, $table, $idQueryColumn)->toSql();

            $last = $this->select([$this->parentIdKey])->whereRaw("$idQueryColumn = (" . $last->toSql() . ')');

        }

        $query = implode("\nUNION\n", $queries);

        $pdoStatement = $this->model->getConnection()->getPdo()->prepare($query);

        return new PDOPrepared($pdoStatement, $query);

    }
307334
private function buildChannelTree($parentId = self::ROOT_CHANNEL_ID)
    {
        $children = $this->getChildren($parentId);
        $children->map(function (Channel $channel) use ($parentId) {
            $channel->setChildren($this->buildChannelTree($channel->getId()));
            if ($parentId != self::ROOT_CHANNEL_ID) {
                $channel->setParent($this->getChannel($parentId));
            }
        });

        return $children;
    }
1107430
protected static function build_tree($all, $parentid) {
        $tree = array();
        foreach ($all as $one) {
            if ($one->get('parentid') == $parentid) {
                $node = new stdClass();
                $node->competency = $one;
                $node->children = self::build_tree($all, $one->get('id'));
                $tree[] = $node;
            }
        }
        return $tree;
    }
292493
public function create($parentId, array $data)
    {
        $resource = $this->createPartialResourceUrlForList($parentId);
        $data = $this->client->post($resource, [$this->getResourceName() => $data]);

        return $this->fromArray(reset($data));
    }
1312420
final protected function parseData(array $data, $parentId = 0)
    {
        $result = array();

        foreach ($data as $subArray) {
            $nested = array();

            if (isset($subArray[$this->childrenKey])) {
                // Recursive call
                $nested = $this->parseData($subArray[$this->childrenKey], $subArray[RelationBuilder::TREE_PARAM_ID]);
            }

            $result[] = array(
                RelationBuilder::TREE_PARAM_ID => $subArray[RelationBuilder::TREE_PARAM_ID], 
                RelationBuilder::TREE_PARAM_PARENT_ID => $parentId
            );

            $result = array_merge($result, $nested);
        }

        return $result;
    }
378848
public function removeInBelongsToManyRelationship(string $parentId, string $name, iterable $childIds): int
    {
        // Check that relationship is `BelongsToMany`
        assert(call_user_func(function () use ($name): bool {
            $relType = $this->getModelSchemas()->getRelationshipType($this->getModelClass(), $name);
            $errMsg  = "Relationship `$name` of class `" . $this->getModelClass() .
                '` either is not `belongsToMany` or do not exist in the class.';
            $isOk = $relType === RelationshipTypes::BELONGS_TO_MANY;

            assert($isOk, $errMsg);

            return $isOk;
        }));

        return $this->removeInToManyRelationship($this->getConnection(), $parentId, $name, $childIds);
    }
456887
private function getAllChildRoleIds($parentIds)
    {
        $allChildIds = [];

        while (count($parentIds) > 0) {
            $parentIds = $this->getChildIds($parentIds);
            $allChildIds = ArrayHelper::merge($allChildIds, $parentIds);
        };

        return $allChildIds;
    }
641820
public function getTermsTreeData($parentID = 0)
    {
        $tree = Hierarchy::getTree($this->id);

        $data = [];

        static::mapTreeDataRecursive($tree, $data, $parentID);

        return $data;
    }
609981
public function getRoot($categoryId)
    {
        $category = CategoryQuery::create()->findPk($categoryId);

        if (0 !== $category->getParent()) {
            $parentCategory = CategoryQuery::create()->findPk($category->getParent());

            if (null !== $parentCategory) {
                $categoryId = $this->getRoot($parentCategory->getId());
            }
        }

        return $categoryId;
    }
263895
public function parentGuid($guid)
    {
        $model = $this->noInitModel;
        if (!is_string($model->parentAttribute)) {
            return $this;
        }
        if ($guid instanceof $model) {
            $guid = $guid->getGUID();
        }
        return $this->andWhere([$model->parentAttribute => $guid]);
    }
1375052
public function getNameValueMapByType( $parentId, $parentType, $type ) {

		$config = [];

		$config[ 'conditions' ][ 'parentId' ]	= $parentId;
		$config[ 'conditions' ][ 'parentType' ] = $parentType;
		$config[ 'conditions' ][ 'type' ]		= $type;

		return $this->getNameValueMap( $config );
	}
578589
public function getActiveCategoryIdList( $categoryId, $parentType ) {

		$modelClass	= static::$modelClass;

		$models = $modelClass::findActiveByCategoryIdParentType( $categoryId, $parentType );
		$ids	= [];

		foreach ( $models as $model ) {

			$category = $model->category;

			$ids[] = $category->id;
		}

		return $ids;
	}
1337960
public function findChildrenByParentId($parent_id)
    {
        $qb = $this->createQueryBuilder();
        $qb->andWhere($qb->getRootAliases()[0] . '.parent = ' . $this->addNamedParameter('parent', $parent_id, $qb))
            ->orderBy($qb->getRootAliases()[0] . '.position', 'ASC');
        return $qb->getQuery()->getResult();
    }
478597
public static function findByUser( $parentId, $parentType, $userId, $type = ModelComment::TYPE_COMMENT ) {

		return static::find()->where( 'parentId=:pid AND parentType=:ptype AND createdBy=:uid AND type=:type', [ ':pid' => $parentId, ':ptype' => $parentType, ':uid' => $userId, ':type' => $type ] )->one();
	}