I know we should use service contracts(Repository) over $model->load(), but in Repository itself, how to replace the deprecated load() function?

For example, in Magento\Cms\Model\PageRepository, the official Magento 2.1.9 used the deprecated load() function too.

public function getById($pageId)
    $page = $this->pageFactory->create();
    if (!$page->getId()) {
        throw new NoSuchEntityException(__('CMS Page with id "%1" does not exist.', $pageId));
    return $page;


When Should We Use a Repository and Factory in Magento 2?

Is there ever a reason to prefer $model->load() over service contracts?

1 Answer 1


You can use ResourceModel's load() instead, which extends Magento\Framework\EntityManager\EntityManager's load() method.

We could see a example in: Magento\Cms\Model\BlockRepository

public function getById($blockId)
        $block = $this->blockFactory->create();
        $this->resource->load($block, $blockId);
        if (!$block->getId()) {
            throw new NoSuchEntityException(__('CMS Block with id "%1" does not exist.', $blockId));
        return $block;
  • Thanks, accept and my vote ran out today. repositoryModel? It should be ResourceModel, right?
    – Key Shang
    Dec 4, 2017 at 3:13
  • ResourceModel's load() which extends Magento\Framework\EntityManager\EntityManager's load() method
    – Key Shang
    Dec 4, 2017 at 3:21
  • yeah, that was my bad. can say a typo :) Dec 4, 2017 at 4:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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