Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/58.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Cakephp不会重置要保存的模型_Php_Mysql_Cakephp - Fatal编程技术网

Cakephp不会重置要保存的模型

Cakephp不会重置要保存的模型,php,mysql,cakephp,Php,Mysql,Cakephp,我对cakephp有问题。我有一个数据库表,它有一个借方和贷方列。下面,我尝试从第一个用户帐户中扣除款项并保存记录。如果保存成功,它将更改相同的数组,并将所有者id更改为钱将要存入的用户id,从而使借方成为贷方。问题是这个 不正确 user_id payment_to_id credit debit 1 2 0.00 3.00 1 2 3.00 0.00 下面是它应该如何显示。由于用户_id 2正在接收资金,因此付

我对cakephp有问题。我有一个数据库表,它有一个借方和贷方列。下面,我尝试从第一个用户帐户中扣除款项并保存记录。如果保存成功,它将更改相同的数组,并将所有者id更改为钱将要存入的用户id,从而使借方成为贷方。问题是这个

不正确

user_id payment_to_id credit debit
1       2             0.00   3.00
1       2             3.00   0.00
下面是它应该如何显示。由于用户_id 2正在接收资金,因此付款_to_id保留为空。但它不是这样工作的。它的工作原理与上面显示的一样,这是不正确的。我正在使用create()方法创建一个新记录,但它不起作用。我做错了什么

user_id payment_to_id credit debit
1       2             0.00   3.00
2       null          3.00   0.00
下面是代码

    function advanced_transfer($data = array()) {
        if(!empty($data)) {
            //I store the original credit in a variable called credit
            $credit = $data['PaymentTransaction']['credit'];
            //since I have credit stored, a zero it out so it wont save
            $data['PaymentTransaction']['credit'] = 0;
            //then I first set up a debit transaction
            $data['PaymentTransaction']['debit'] = $credit;
            //I am storing both the account owner and payment to id's
            $accountOwnerId = $data['PaymentTransaction']['user_id'];
            $paymentToId = $data['PaymentTransaction']['payment_to_id'];
            $this->create();//new record
            if($this->save($data, false)) {//save
                $data['PaymentTransaction']['user_id'] = $paymentToId;//I set the owner to the payment to user
                $data['PaymentTransaction']['payment_to_id'] = null;//I null out payment to cause the user is recieving
                $data['PaymentTransaction']['credit'] = $credit;//I set theirs to credit
                $data['PaymentTransaction']['debit'] = 0;//and null out debit cause we arent taking out
                $this->create();//create new record
                if(!$this->save($data, false)) {//save with no validation again
                    return false;
                }
            } else {
                return false;
            }
        } else {
            return false;
        }

        return true;
    }

你能给我们看一下你的
支付\u交易
表的模式转储吗?我发现了这个问题。它表明问题实际上发生在这个方法调用之外。发生了另一次保存,由于未调用create(),因此它重写了上一次保存。