CakePHP模型 - > save()不存储在DB中

时间:2018-02-22 17:53:04

标签: php postgresql cakephp pgadmin

我正在尝试将一些数据保存到模型中。

这是表格:

CREATE TABLE "user_dashboard_configs"(
"user_dashboard_config_id" serial NOT NULL,
"user_id" integer,
"module_id" integer,
"graphic_id" integer,
"dc_show" boolean,
"graphic_type" varchar(20),
CONSTRAINT "user_dashboard_configs_pkey" PRIMARY 
KEY("user_dashboard_config_id"),
)

这是模特:

class UserDashboardConfig extends AppModel {

public $name = 'UserDashboardConfig';
//public $useTable = 'user_dashboard_configs';
public $primaryKey = 'user_dashboard_config_id';

var $belongsTo = array(
    'Module' => array(
        'className' => 'Module',
        'foreignKey' => 'module_id',
    ),
    'User' => array(
        'className' => 'User',
        'foreignKey' => 'user_id'
    )
);
}

add()函数

...
$this->UserDashboardConfig->create();
$save['UserDashboardConfig']['user_id'] = intval($request['user_id']);
...
$save['UserDashboardConfig']['graphic_type'] = $value;
$this->UserDashboardConfig->save($save);
...
// also tried with
// $this->UserDashboardConfig->set(array(
//             'user_id' => intval($request['user_id'],
//              ...
//          )));

此调试:

debug($this->UserDashboardConfig->getDataSource()->getLog(false, false));

返回:

    (int) 8 => array(
        'query' => 'BEGIN',
        'params' => array(),
        'affected' => (int) 0,
        'numRows' => (int) 0,
        'took' => (float) 1
    ),
    (int) 9 => array(
        'query' => 'INSERT INTO "public"."user_dashboard_configs" ("user_id", "module_id", "graphic_id", "dc_show", "graphic_type") VALUES (4, 57, 6, 'FALSE', 'bar_line')',
        'params' => array(),
        'affected' => (int) 1,
        'numRows' => (int) 1,
        'took' => (float) 0
    ),
    (int) 10 => array(
        'query' => 'COMMIT',
        'params' => array(),
        'affected' => (int) 1,
        'numRows' => (int) 1,
        'took' => (float) 0
    )

粘贴到pgAdmin时INSERT指令正确存储数据,但CakePHP不存储它,尽管没有抛出错误。 刚注意到这一点:数据库上的序列正在增加,因此存在一种插入,但数据未显示在表中。 这可能是postgresql / phAdmin问题吗?

有人可以帮忙解决这个问题吗? 已经尝试过:

https://stackoverflow.com/a/10198674/5525602

https://stackoverflow.com/a/20502819/5525602

https://stackoverflow.com/a/20824941/5525602

http://headynation.com/cakephp-model-save-function-returning-false-without-an-error-or-sql-statements/

0 个答案:

没有答案