Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

Trouble With getSequenceName

I'm pretty new to Phalcon and am really enjoying working with it. However, I've run across an issue that I can't seem to resolve. Based on my research, the answer seems simple, yet it eludes me.

I have the following model with a sequence that doesn't match the default (notice the capital I in Id). Obviously, I have implemented getSequenceName, but I still get an error every time I try to insert a record.

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42P01]: Undefined table: 7 ERROR: relation "testtestidseq" does not exist'

Database is Postrgres. What am I missing?

class Test extends Phalcon\Mvc\Model
{
    public function initialize()
    {
        //echo $this->sequenceName;
    }

    public function getSequenceName()
    {
        return "test_testId_seq";
    }
}

Thanks in advance.



83.4k

Did you set the default schema in your connection settings?

Phalcon,

Thanks for the reply. Unless you mean something different than the following, yes I did.

    $di->set('db', function() use ($config) {
        return new \Phalcon\Db\Adapter\Pdo\Postgresql(array(
                "host" => $config->database->host,
                "username" => $config->database->username,
                "password" => $config->database->password,
                "dbname" => $config->database->name,
                "schema" => 'public'
        ));
    });

I did notice the record gets created correctly even when the exception is thrown.

I also found that returning the sequence name in double quotes as follows works. This is not ideal and it probably points to my issue being specific to pgsql.

    public function getSequenceName()
    {
        return "\"test_testId_seq\"";
    }
edited Jul '14

Whoops, I guess I should have replied, rather than just adding a new comment.

Phalcon,

Thanks for the reply. Unless you mean something different than the following, yes I did.

$di->set('db', function() use ($config) {
    return new \Phalcon\Db\Adapter\Pdo\Postgresql(array(
    "host" => $config->database->host,
    "username" => $config->database->username,
    "password" => $config->database->password,
    "dbname" => $config->database->name,
    "schema" => 'public'
    ));
});

I did notice the record gets created correctly even when the exception is thrown.

I also found that returning the sequence name in double quotes as follows works. This is not ideal and it probably points to my issue being specific to pgsql.

public function getSequenceName()
{
    return "\"test_testId_seq\"";
}

Hello,

I tried to use the same approach but nothing works. My configs are exactly like the presented by trparham. Sequence has the right owner, etc.

Any idea?



588
Accepted
answer
edited Jul '14

Paulo,

It seems to be specific to PostgreSQL. As I stated previously, I was able to get around it by escaping the sequence name.

    public function getSequenceName() {
        return "\"some_test_table_tableId_seq\"";
    }

Is that approach not working for you? You might want to double check your sequence name.

Good Luck!