1

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
3

It would be something like this:

$consumptionCollection = $this->_consumptionFactory->create();
$consumptionCollection->addFieldToFilter(
                            'filter1',
                            array(
                                'eq' => $var1)
                        )
                        ->addFieldToFilter(
                            'filter2',
                            array('eq' => $var2)
                        );
$consumptionCollection->load();
  • 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
0

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

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

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.