[英]update table using join codeigniter active record?
here is a snippet of my code using active record to update the item_stock values. 这是我的代码片段,使用活动记录来更新item_stock值。 I need to get the item.SKU from item table as selector to my query.
我需要从项目表中获取item.SKU作为查询的选择器。
$this->db->join('item','item.item_id = items.item_id')
->join('items','items.stock_id = item_stock.stock_id')
->set('item_stock.stock_quantity','item_stock.stock_quantity + $new_qty',FALSE)
->where('item_stock.colour',$color)
->where('item_stock.size',$size)
->where('item.SKU',$SKU)
->update('item_stock');
$query = $this->db->update('item_stock');
for some reason it lost it's JOIN stack. 由于某种原因,它丢失了JOIN堆栈。
Error Number: 1054
Unknown column 'item.SKU' in 'where clause'
UPDATE `item_stock` SET `item_stock`.`stock_quantity` = item_stock.stock_quantity + $new_qty WHERE `item_stock`.`colour` = 'Kuning' AND `item_stock`.`size` = 'XL' AND `item`.`SKU` = 'Wooser-01'
Filename: E:\xampp\htdocs\nekogear\system\database\DB_driver.php
Line Number: 330
any tips how to overcome this problem? 有什么技巧如何克服这个问题? thanks before.
之前感谢。
* ps = I've try the $this->db->query("query code here") and it works fine, but I want to use the active record style for the consistency. * ps =我尝试使用$ this-> db-> query(“此处的查询代码”) ,它可以正常工作,但是我想使用活动记录样式来保持一致性。
Call me stupid but hey, it's works! 叫我愚蠢,但嘿,行得通! My "solution" is to include the JOIN in the $this->db->update()
我的“解决方案”是将JOIN包含在$ this-> db-> update()中
$this->db->set('item_stock.stock_quantity','item_stock.stock_quantity + $new_qty',FALSE)
->where('item_stock.colour',$color)
->where('item_stock.size',$size)
->where('item.SKU',$SKU);
$query = $this->db->update('item_stock JOIN items ON items.stock_id = item_stock.stock_id JOIN item ON item.item_id = items.item_id');
Its equal to the following query 它等于以下查询
UPDATE `item_stock`
JOIN items ON items.stock_id = item_stock.stock_id
JOIN item ON item.item_id = items.item_id
SET `item_stock`.`stock_quantity` = item_stock.stock_quantity + $new_qty
WHERE `item_stock`.`colour` = 'Kuning'
AND `item_stock`.`size` = 'XL'
AND `item`.`SKU` = 'Wooser-01'
Hope it will helps you too! 希望它也会对您有帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.