Skip to content

Use Custom Module collection in other custom Module magento 2

I want collection of one module in other module. I am doing it like

use TestCompanyAddressesModelCompanyAddressFactory;

class ReformatTelephoneField implements DataPatchInterface
{
    protected $companyAddressFactory;

    /**
     * @param CompanyAddressFactory $companyAddressFactory
     */
    public function __construct(
        CompanyAddressFactory $companyAddressFactory
    ) {
        $this->companyAddressFactory = $companyAddressFactory;
    }

public function apply()
    {
        $companyAddressCollection = $this->companyAddressFactory->create()->getCollection();
    }
}

I have provided basic code logic that how I am getting collection but on setup:upgrade I am getting issue like Model collection resource name is not defined. Don’t know what is the issue.