Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ID not returned from REST API #14

Open
mklappen opened this issue Oct 18, 2016 · 2 comments
Open

ID not returned from REST API #14

mklappen opened this issue Oct 18, 2016 · 2 comments

Comments

@mklappen
Copy link

mklappen commented Oct 18, 2016

Hi
I have a CakePHP REST API setup with this Oracle driver plugin and it's been working fine for months. That is records are inserted, and retrieved without issue.

However there is one minor issue when performing a POST request (add action). The JSON returned never returns the newly created ID from Oracle. I'm setup on Oracle 11g and have necessary sequence/triggers setup to create new IDs upon insert but all I ever receive is the response below w/ ID = 0:

{ "success": true, "data": { "id": 0 } }

With same code using MySQL the ID is always returned.
I'm using Crud Add action for the REST post request to insert new record.

Just wondering if anyone else has experienced this and if there's a solution (and if it is from oracle side or not).

Thanks in advance.

@snelg
Copy link
Owner

snelg commented Oct 18, 2016

Just pushed an update that will automagically set the new id if the sequence is named {tablename}_ID_SEQ.
If the sequence has some other name, then you'll have to manually call the "lastInsertId" function, probably in the table's afterSave function. Something like

    public function afterSave($event, $record, $options)
    {
        if ($record->isNew()) {
            $record->id = $this->connection()->driver()->lastInsertId("SEQUENCE_NAME");
        }
    }

@mklappen
Copy link
Author

Thanks! Sequence name did not match the pattern, so adding it manually into the afterSave worked.

Will try to test out on another dummy table/sequence setup as {tablename}_ID_SEQ.

Thanks again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants