问题
When I try save some information in Postgres table, CakePHP return this error for me:
array(
(int) 0 => '[PDOException] SQLSTATE[42P01]: Undefined table: 7 ERRO: relação "public.cashier_transaction_transaction_num_seq" não existe
Request URL: /www/cashiers/open
Stack Trace:
But CakePHP is correctly: this sequence doesn't exist. The correct sequence is transaction_num_seq.
How can I change that IN CAKE (I can't change the database).
回答1:
There seems to be an undocumented, optional attribute used by the describe($model) function in Postgres.php
if (isset($model->sequence)) {
$this->_sequenceMap[$table][$model->primaryKey] = $model->sequence;
}
Use it, like so, to specify the sequence of the table's primary key.
public class YourModel extends AppModel {
public $sequence = 'public.foobar_seq';
...
}
回答2:
The only way I found to fix this error, was creating an action in each model named "nextval ()" for example, and run the default PostgreSQL query to get the next sequence.
public function nextval() {
$sql = "select nextval('transaction_num_seq') as nextval";
$result = $this->query($sql);
return $result[0][0]['nextval'];
}
来源:https://stackoverflow.com/questions/14965410/cakephp-use-wrong-sequence-name-postgresql