I'm trying to save some data into a model.
This is the table:
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"),
)
This is the Model:
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'
)
);
}
And the add() function
...
$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'],
// ...
// )));
This debug:
debug($this->UserDashboardConfig->getDataSource()->getLog(false, false));
Returns:
(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
)
The INSERT instruction when pasted into pgAdmin stores the data correctly, but CakePHP does not store it, despite not throwing errors. Just noticed this: the sequence on the DB is increasing, so there is kind of an insert, but the data is not shown on the table. Could this be a postgresql / phAdmin problem?
Can someone help on how to solve this? Already tried:
https://stackoverflow.com/a/10198674/5525602
https://stackoverflow.com/a/20502819/5525602