I have a model named purchaseorder which have some purchase orders. Each purchase order have product and quantity of each product. I tried a system where I can receive the purchase order and my stock quantity get updated by purchase order quantity. I have a separate model named Stock. But I am not being able to update stock quantity using activerecords update function. Below is my code,
$model = $this->findModel($id);
$item = Stock::findOne($model->order_item);
$item->quantity = $item->quantity + $model->order_item_quantity;
$item->update();
order_item works as product id to find the stock item that I intend to update. order_item_quantity is purchase order quantity.
It does not show any error. Does not work either. Does anybody have any idea why this is not working?
I am doing it on yii 2.0.2.