How to Get Bundle Item Parent id by option id in Magento 2?

When you are working with the Bundle Product related customization and you required to parent product id by the Option id, You can easily achieve it by the option id with some programming stuff.

Each Bundle Product generated by the combines of options selection. Each option contains the list of a product like a simple or virtual.

You can retrieve the Bundle Id called parent product id using the below code snippet,

<?php
namespace Jesadiya\ParentBundleId\Model;

use Magento\Bundle\Model\ResourceModel\Option\CollectionFactory;

class ParentBundleId
{
    /**
     * @var CollectionFactory
     */
    private $collectionFactory;

    public function __construct(
        CollectionFactory $collectionFactory
    ) {
        $this->collectionFactory = $collectionFactory;
    }

    /**
     * get Parent Bundle product id by option id
     *
     * @param int $optionId
     * @return int|null
     */
    public function getParentItemIdByOptionId(int $optionId)
    {
        $collection = $this->collectionFactory->create();
        $collection->addFieldToFilter('option_id', ['eq'=>$optionId])->getFirstItem();

        $parentId = null;
        foreach ($collection as $record) {
            $parentId = (int)$record->getParentId();
        }
        return $parentId;
    }
}

You can get the parent id by,

$id = 1;
echo $parentId = $this->getParentItemIdByOptionId($id);

Output:
52