1

I have a custom module with a few tables. I have the model, resource model and collection classes in place. If I try to access the contents of the table, I am getting this error

Type Error occurred when creating object: Vendor\ModuleModel\ResourceModel\AddressGroups\Collection\Interceptor, Argument 5 passed to Vendor\Module\Model\ResourceModel\AddressGroups\Collection\Interceptor::__construct() must implement interface Magento\Framework\DB\Adapter\AdapterInterface or be null, string given, called in /home/user/magentoTest/vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php on line 121

I'm getting this error only in production mode. If I switch to developer mode, everything seems to be working fine.

This is my collection.php

<?php
namespace Vendor\Module\Model\ResourceModel\AddressGroups;

class Collection extends \Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection{

    public function _construct(){
        $this->_init('Vendor\Module\Model\AddressGroups', 'Vendor\Module\Model\ResourceModel\AddressGroups');
    }
}
1
  • please post your Collection.php file – Rk Rathod Jan 30 at 6:19
0

For one thing, to be sure you are passing the right args into the function in your file, dont directly enter classnames as strings. Do this, as it is best practice.

Also, the visibility on _construct should be protected. You have public.

<?php

namespace Vendor\Module\Model\ResourceModel\AddressGroups;

class Collection extends \Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection
{
    protected function _construct(){
        $this->_init(\Vendor\Module\Model\AddressGroups::class, \Vendor\Module\Model\ResourceModel\AddressGroups::class);
    }
}

Beyond that, delete the generated/code/Vendor/Module directory. Sometimes, when you update a class's constructor or anything that affects the Interceptor class, you might need to delete filed from generated/code.

The error you posted makes it sound like you had a constructor in your class and possibly you removed it.

1
  • Thanks for your answer but I never had a constructor in this class – coderGeek Feb 1 at 16:50
0

I have exactly the same issue on Magento 2.3, It works in developer mode, not in production.

I deleted the generated/code/Vendor/Module directory

Doesnt change much

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.