How can I update record with multiple where clause? I know below method to update record with single where condition. I tried to used addFieldToFilter() but not succeeded.

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$order_ = $objectManager->create('<ext_name>\<module_name>\Model\OrderSaleslist')

I want to apply below query.

Update ordersaleslist set seller_order_confirm = 'dispatched', payment_mode = 'COD' where order_id = 1 and product_id = 20 and (status !='' OR dispatched_status!='');

Thanks in Advance.

3 Answers 3


you can apply multiple where with AND logic


    $collections = $this->_yourFactory->create()->getCollection()
                 ->addFieldToFilter('order_id', array('eq' => '1'))
                 ->addFieldToFilter('product_id', array('eq' => '20'));
    foreach($collections as $item)

object manager is not recommended. load and save methods are deprecated for best practice you should use service contracts. for more info refer this link

namespace Vendor\MyModule\Model;

use Magento\Framework\Model\AbstractModel;
 class Products extends AbstractModel
        protected function _construct()

        public function setProduct($newProductId){    
           $collection = $this->getCollection()->addFieldToFilter('product_id', $);

I update product Id using collection in magento2 I called setProduct() from the controller.

main logic to update is

 $collection = $this->getCollection()->addFieldToFilter('product_id', $);

You have used two time


just use once $order_->setSellerOrderConfirm("dispatched").

if not work then you can use like this,

$order_->addFieldToFilter('order_id ', array('eq' => 1));

May be it will help you.

  • Thanks, I am not looking for this, Please check query. I want multiple where condition for update record
    – Dev
    Nov 17, 2016 at 6:14
  • you can use addFieldToFilter as many time as you want. Nov 17, 2016 at 6:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.