cancel
Showing results for 
Search instead for 
Did you mean: 

What is the use of load() method in collection?

What is the use of load() method in collection?

CASE

productCollectionFactory load function gives data in query but not in object

$collection = $this->_productCollectionFactory->create()
            ->addAttributeToFilter('status', '1')
            ->addAttributeToFilter('featured', '1')
            ->addAttributeToFilter('type_id',["neq"=>"configurable"]);

and after this i calling load() function

$collection->addAttributeToSelect('*')->load();

and after that applying JOIN's

$collection->getSelect()->join(
                ['cp' => $collection->getTable('custom_product')], 'e.entity_id = cp.marketplace_product_id'
        );

and some other JOIN's...


$collection->getSelect()->orderRand()->limit(8);

In collection query i am getting perfect query with JOIN table's data.

foreach ($collection as $key => $data){    $responce[$key]['custom_price'] = $data->getCustomSpecialPrice();
}

I am getting all custom_special_price and other JOIN fields DATA IN Query But not in foreach.

But when i don't use load() function it gives me data using get method ,But when i do use load() function it doesn't.

So my question is why Magento loads data in Query ? But not in Object.

 

What load() function is doing with generating query ?

and why those data which is available in query but not in object ?