CakePHP - updateAll填写datefield中的0000-00-00

时间:2013-11-29 11:28:23

标签: mysql cakephp

在我正在创建的应用程序中,有一个点正在制作大量记录。这些记录计算创建的金额。有一个日期将显示上次更新日期 但是,只要有更新,日期就不会更改。即使我把它正确放入,它也将保存为0000-00-00。

这是我的代码的一部分:

$date = date('Y-m-d');

// based on existion, update or create the commission
                    if ( $commission_exists > 0) {

                    //exists, so needs to be updated instead of created
                    $this->Commission->updateAll(array( // THIS ONE DOES NOT WORK
                        'commission_rel_client' => $position['Position']['position_rel_client'],
                        'commission_rel_account' => $position['Position']['position_id'],
                        'commission_date' => $date,
                        'commission_value01' => '1.23',
                        'commission_value02' => '4.56',
                        'commission_value03' => '7.89',
                        'commission_value04' => '0.12',
                        'commission_value05' => '3.45',
                        'commission_value06' => '6.78',
                        'commission_value07' => '9.01',
                        'commission_value08' => '1.23',
                        'commission_value09' => '4.56',
                        'commission_value10' => '7.89',
                        'commission_value11' => '0.12',
                        'commission_value12' => '3.45',
                        'commission_value13' => '6.78',
                        'commission_value14' => '9.01',
                        'commission_total' => '200'
                    ), array('commission_rel_account' => $position['Position']['position_id']));
                }
                else {
                    // save commission record
                    $this->Commission->create();
                    $this->Commission->save(array( // THIS ONE WORKS
                        'commission_rel_client' => $position['Position']['position_rel_client'],
                        'commission_rel_account' => $position['Position']['position_id'],
                        'commission_date' => $date,
                        'commission_value01' => '1.23',
                        'commission_value02' => '4.56',
                        'commission_value03' => '7.89',
                        'commission_value04' => '0.12',
                        'commission_value05' => '3.45',
                        'commission_value06' => '6.78',
                        'commission_value07' => '9.01',
                        'commission_value08' => '1.23',
                        'commission_value09' => '4.56',
                        'commission_value10' => '7.89',
                        'commission_value11' => '0.12',
                        'commission_value12' => '3.45',
                        'commission_value13' => '6.78',
                        'commission_value14' => '9.01',
                        'commission_total' => '200'
                    ));
                }

不要介意价值观,只考虑测试数据。我只是想知道我的代码有什么“错误”,因为它对我来说似乎完全没问题 我也尝试过updateField,虽然有效但不能在这里使用,因为我的记录在某个字段上被过滤而不是id(是的,听起来很奇怪,我知道。不要质疑我的愚蠢逻辑。)。< / p>

1 个答案:

答案 0 :(得分:2)

根据documentation,您应该尝试定义引号之间的日期

$this->Ticket->updateAll(
    array('Ticket.status' => "'" . $data . "'"),
    array('Ticket.customer_id' => 453)
);