Skip to content

Instantly share code, notes, and snippets.

@pkese
Created July 12, 2016 16:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pkese/e2ed4b2553b1b5bb365cd0b779d22bbe to your computer and use it in GitHub Desktop.
Save pkese/e2ed4b2553b1b5bb365cd0b779d22bbe to your computer and use it in GitHub Desktop.

I have setup a table with custom id field as follows:

  app.use('session', new Service({
    Model: r,
    db,
    id: 'hash',
    name: 'sessions',
  }));

Then I create new entries with preset hash (id) field:
app.service('session').create({hash:'123456', ...})

And I get the above error.

I have managed to replace the following code in function create(data):

      return this.table.insert(data).run().then(function (res) {
        return Object.assign({
          id: data.id ? data.id : res.generated_keys[0]
        }, data);
      });

with

      const idField = this.id;
      return this.table.insert(data).run().then(function (res) {
        const result = Object.assign({}, data);
        if (!data[idField]) result[idField] = res.generated_keys[0];
        return result;
      });

... and things appear to work.

However there are similar problems in patch and update.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment