Retrieve products relations by childrens

@param array $childrenIds The product ids being reindexed

@return array
509519
public function getRelationsByChild($childrenIds)
    {
        $metadata      = $this->getEntityMetaData(\Magento\Catalog\Api\Data\ProductInterface::class);
        $entityTable   = $this->getTable($metadata->getEntityTable());
        $relationTable = $this->getTable('catalog_product_relation');
        $joinCondition = sprintf('relation.parent_id = entity.%s', $metadata->getLinkField());

        $select = $this->getConnection()->select()
            ->from(['relation' => $relationTable], [])
            ->join(['entity' => $entityTable], $joinCondition, [$metadata->getIdentifierField()])
            ->where('child_id IN(?)', array_map('intval', $childrenIds));

        return $this->getConnection()->fetchCol($select);
    }
944221
public function get_all_children_ids() {
        $children = [];
        $walk = [$this->id];
        while (count($walk) > 0) {
            $catid = array_pop($walk);
            $directchildren = self::get_tree($catid);
            if ($directchildren !== false && count($directchildren) > 0) {
                $walk = array_merge($walk, $directchildren);
                $children = array_merge($children, $directchildren);
            }
        }

        return $children;
    }
1086732
public function getChildren(array $columns = ['*'])
    {
        if ($this->hasChildrenRelation()) {
            $result = $this->getRelation($this->getChildrenRelationIndex());
        } else {
            $result = $this->children()->get($columns);
        }

        return $result;
    }
1183487
public function GetAllChildrenIds()
    {
        $aChildIdList = $this->GetFromInternalCache('aChildIdList');
        if (null !== $aChildIdList) {
            return $aChildIdList;
        }
        $aChildIdList = array();
        $oChildren = &$this->GetChildren();
        while ($oChild = &$oChildren->Next()) {
            $aChildIdList[] = $oChild->id;
            $aChildChildIdList = $oChild->GetAllChildrenIds();
            $aChildIdList = array_merge($aChildIdList, $aChildChildIdList);
        }
        $this->SetInternalCache('aChildIdList', $aChildIdList);

        return $aChildIdList;
    }
1202551
public function getChildOrganizations($parentId = null)
    {
        static $children;

        if (is_null($parentId)) {
            return array();
        }

        if (! isset($children[$parentId])) {
            $organizations = $this->db->fetchPairs(
                    'SELECT gor_id_organization, gor_name
                        FROM gems__organizations
                        WHERE gor_active=1 AND gor_has_login=1 AND
                            (gor_accessible_by LIKE ' . $this->db->quote('%:' . $parentId . ':%') . ' OR
                                gor_id_organization = ' . $this->db->quote($parentId) .  ')
                            ORDER BY gor_name');

            natsort($organizations);

            $children[$parentId] = $organizations;
        }

        return $children[$parentId];
    }
424355
public function getChildNodes($dsId, $level = 1)
    {
        $children = [];

        $childrenDsIds = $this->getChildrenDsIds($dsId, $level);
        foreach ($childrenDsIds as $childDsId) {
            $children[] = $this->getNode($childDsId);
        }

        return $children;
    }
81419
public function getChildrenUpdaters(): array {
        $key = get_class($this);
        if(!array_key_exists($key, self::$childrenUpdaters)) {
            return [];
        }
        return self::$childrenUpdaters[$key];
    }
542812
public function children()
    {
        $children = $this->getAttribute('children') ?: [];

        if ($children && ! is_array($children) && ! ($children instanceof Collection)) {
            return (array) $children;
        }

        return $children;
    }
1063719
public function findById($id)
    {
        $result = array();
        $relations = $this->getRelations();

        $items = $relations[RelationBuilder::TREE_PARAM_ITEMS];

        if (isset($items[$id])) {
            return $items[$id];
        } else {
            return false;
        }
    }
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();
		}
239707
public function getNonExistingRelated(array $relationships): array
    {
        $nonExisting = [];

        foreach ($relationships as $relation) {
            if ($this->hasAttribute($relation) && array_key_exists($relation, $this->relationships)) {
                $nonExisting = array_merge($nonExisting, $this->getNonExistingFromRelation($relation));
            }
        }

        return $nonExisting;
    }
958756
public function getChilds()
    {
        if (config('menus.ordering')) {
            return collect($this->childs)->sortBy(function ($child) {
                return $child->order;
            })->all();
        }

        return $this->childs;
    }
875471
public function children()
    {
        $result = [];
        foreach ($this->children as $childGroup) {
            $result = array_merge($result, $childGroup);
        }

        return $result;
    }
615469
public function getRelatedNodeIds($ids)
    {
        $cols = array(
                'story_object_id' ,
                'story_subject_id',
                'story_comment_id',
                'story_target_id' ,
                'parent_id',
                'owner_id',
        );

        foreach ($cols as $key => $value) {
            $cols[$key] = $value.' IN ('.implode(',', $ids).')';
        }

        $cols = implode(' OR ', $cols);

        //all the nodes ids that are somehow related to deleted nodes
        //possible objects (comments/stories/medium nodes)
        $nids = $this->getService('repos:base.node')
                    ->getQuery()
                    ->disableChain()
                    ->where($cols)->fetchValues('id');

        if (!empty($nids)) {
            $story_ids = $this->getService('repos:stories.story')->getQuery()->disableChain()->where(array('object.id' => $nids))->fetchValues('id');
            $nids = array_merge($nids, $story_ids);

            //if there are any medium nodes in the related nodes
            //check if they have any comments
            $comment_ids = $this->getService('repos:base.comment')->getQuery()->disableChain()->where(array('parent.id' => $nids))->fetchValues('id');
            $nids = array_merge($nids, $comment_ids);
        }

        return array_unique($nids);
    }
1014945
public function handleChildrenProductId($args)
    {
        $productId = $args['row']['product_id'];
        $parentId = $args['row']['parent_id'];
        if (!array_key_exists($parentId, $this->childrenProductIds)) {
            $this->childrenProductIds[$parentId] = [];
        }
        $this->childrenProductIds[$parentId][] = $productId;
    }
870235
public function getAllChildren($parentID)
    {
        $children = $this->getChildren($parentID);
        foreach ($children as $key => $child){
            $this->categoriesToBeDeleted[$child->categoryID] = $child;
            $this->getAllChildren($child->categoryID);
        }
    }
1045564
protected function getTree($storeIds)
    {
        $filter = implode(',', $storeIds);
        if (isset($this->storeTrees[$filter])) {
            return $this->storeTrees[$filter];
        }

        $data = [];
        $stores = $this->storeManager->getStores(true);
        foreach ($stores as $store) {
            if (in_array($store->getId(), $storeIds)) {
                $data[$store->getId()] = $this->getStoreOptions($store);
            } elseif ($filter == 0) {
                $data[$store->getId()] = $this->getStoreOptions($store);
            }
        }

        $this->storeTrees[$filter] = $data;

        return $this->storeTrees[$filter];
    }