How can I add more than one field in the load method of the \Magento\Framework\Model\AbstractModel

$consumptionCollection = $this->_consumptionFactory->create()->load($iccid, 'iccid');

I want to filter the model collection for more than one field

  • You want to filter collection or model? – Amit Bera Aug 15 '18 at 16:01

It would be something like this:

$consumptionCollection = $this->_consumptionFactory->create();
                                'eq' => $var1)
                            array('eq' => $var2)
  • I can't find the addFieldToFilter method. And give me an invalid method error if i use it – open-ecommerce.org Aug 16 '18 at 9:51
  • What is the _consumptionFactory type? – Chris Anderson Aug 16 '18 at 16:04

In the following sample there I am filtering by 2 fields from the database: field1 and field2

$consumptionCollection = $this->_consumptionFactory->create();
->addFieldToFilter('field1', array('eq' => 'value1'))
->addFieldToFilter('field2', array('eq' => 'value2'))

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.