Dismiss
Announcing Stack Overflow Documentation

We started with Q&A. Technical documentation is next, and we need your help.

Whether you're a beginner or an experienced developer, you can contribute.

Sign up and start helping → Learn more about Documentation →

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).

share|improve this question

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';
    ...
}
share|improve this answer
    
Hmm, interesting. Actually I had not noticed it. Thank you my friend. – Patrick Maciel Aug 23 '13 at 11:44
up vote 0 down vote accepted

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'];
}
share|improve this answer
    
Take a look at this maybe it could help you stackoverflow.com/a/12806856/1695418 – icebreaker Sep 2 '13 at 11:17

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.