Showing results for 
Search instead for 
Did you mean: 

Custom module collection not working

Custom module collection not working

I'm trying to follow Alan Storm's tutorial here.

The code works fine when I try to insert or retrieve a single record, but it cracks when I use collections. I followed all steps he illustrated in the tutorial, which drives me crazy because only collections wouldn't work!!

public function __construct(
    \Magento\Backend\App\Action\Context $context,
    \Vendor\Mymodule\Model\ConfigurationsFactory $myClass
) {
    $this->myClass = $myClass;

public function execute() {

     $todo = $this->myClass->create();

     $collection = $todo->getCollection();

     foreach($collection as $item)
        var_dump('Item ID: ' . $item->getConfigId());


This gives the following error:
Vendor\Mymodule\Model\Configurations does not extend \Magento\Framework\DataObject

any help would be really appreciated.


Re: Custom module collection not working

You already have the error message:


Vendor\Mymodule\Model\Configurations does not extend \Magento\Framework\DataObject

Only models which extend \Magento\Framework\DataObject can have collections. So, first step is to make your model extend that class (or better: extend \Magento\Framework\Model\AbstractModel which again extends the mentioned class as in Alan Storm's example). If you get more errors, you should upload the whole module.


Andreas von Studnitz, Trainer, Consultant, Developer and CEO of integer_net, Germany.

Re: Custom module collection not working


  I already extended my Model with \Magento\Framework\Model\AbstractModel but still I am getting same error. My model code is 

class Post extends AbstractModel implements PostInterface, IdentityInterface {

Please guide me....