【问题标题】:cakephp not saving update value to related table, but no errorscakephp 没有将更新值保存到相关表,但没有错误
【发布时间】:2010-05-05 11:19:51
【问题描述】:

更新订单功能查找当前订单的所有订单行。
循环通过从库存级别减去订购数量并在 $newstock 中保存新的库存级别值。一切都好。
但不会保存。
回显“成功”和正确的值,但数据库未更新。

订单状态字段会更新,代码语法相同。
它也与 Orderline 具有相同的关系。 (从 Orderline Controller 调用的函数)

表关系为:

'Product'hasMany = array('Orderline');
'Order' hasMany = array('Orderline');
'Orderline' belongsTo = array('Order', 'Product');

function updateOrder(){
  $this->data['Order']['id'] = $this->getOrderid();
  $orderproducts = $this->Orderline->find('all',array('conditions' =>     
                           array('Orderline.order_id' => $this->data['Order']['id'])));

foreach($orderproducts as $orderproduct){
  $newstock = $orderproduct['Product']['stock']-$orderproduct['Orderline']['quantity'];
  $this->data['Product']['stock']= $newstock;

  if( $this->Product->saveAll($this->data)){
    echo "success"  ;
  }else{
    echo "not saved";
  }
}

  $this->data['Order']['status']= 1;
  $this->Order->saveall($this->data);

}

【问题讨论】:

    标签: cakephp save


    【解决方案1】:

    我想补充一点,我在使用 saveAll 时遇到静默保存失败,因为我没有清除 APP/tmp/cache 文件夹。

    【讨论】:

      【解决方案2】:

      解决了。

      它实际上一直在向 Product 表添加新行。

      foreach 循环的 insert 中缺少这一行,提醒它使用当前 Product id 知道在哪里插入新数据。

      $this->data['Product']['id']= $orderproduct['Product']['id'];

      【讨论】:

        猜你喜欢
        • 2011-12-22
        • 1970-01-01
        • 1970-01-01
        • 2014-09-22
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多