0
protected $productCollectionFactory;


public function __construct(
        .....
        \Custom\MyModule\Model\ResourceModel\Product\CollectionFactory $productCollectionFactory,
        ...
    ) {
        $this->productCollectionFactory = $productCollectionFactory;
       ....
    }

   public function execute()
   {
    $collection = $this->productCollectionFactory->create()->load(1)->getData();
    var_dump($collection);
die();
    return $collection;   
    }

Output:

SELECT `main_table`.* FROM `custom_mymodule` AS `main_table`
/home/magento2/Custom/MyModule/Controller/Product/products.php:68:
array (size=1)
  0 => 
    array (size=6)
      'id' => string '1' (length=1)
      'product_name' => string 'Moongoose' (length=30)
      'product_sku' => string 'Moo74' (length=3)
1

It's because you have pass 1 in load() method

Magento\Framework\Data\Collection\AbstractDb check in abstrctDb class

                 public function load($printQuery = false, $logQuery = false)
                    {
                        if ($this->isLoaded()) {
                            return $this;
                        }

                        return $this->loadWithFilter($printQuery, $logQuery);
                    }

if you pass 1 it means $printQuery=true that's why query printed

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.