How to get entity type link field value in Magento 2 Commerce?

In Magento commerce, Retrieve the value of the link field for the specific entity type programmatically to join the database query.

Magento uses $metadata->getLinkField() to get the name of the field for the given entity type using MetadataPool class.

You need to pass the entity type interface to fetch the link field name. When you working with Magento commerce, you required entity link field value instead of table primary key entity_id to join query with other database tables.

namespace Jesadiya\LinkField\Model;

use Magento\Catalog\Api\Data\ProductInterface;
use Magento\Framework\EntityManager\MetadataPool;

class GetLinkField
     * @var MetadataPool
    private $metadataPool;

    public function __construct(
        MetadataPool $metadataPool
    ) {
        $this->metadataPool = $metadataPool;

     * Get link field for the entity_type
     * @return string
    public function getLinkField()
        return $this->metadataPool

echo $linkFieldValue = $this->getLinkField($);

You can pass an interface value to retrieve the link field for the given entity type, for a category, Magento\Catalog\Api\Data\CategoryInterface or rule, Magento\SalesRule\Api\Data\RuleInterface.


row_id is the link field used to Content Staging M2 Commerce functionality.