bookshelf-camelcase icon indicating copy to clipboard operation
bookshelf-camelcase copied to clipboard

idAttribute with underscores fails

Open pyldin601 opened this issue 7 years ago • 2 comments

When you try to define model with custom id containing underscores model always uses insert instead of update method on save.

const Foo = bookshelf.Model.extend({
  tableName: 'foos',
  idAttribute: 'custom_foo_id',
  ...
});

This code broken:

        // After a successful database save, the id is updated if the model was created
        if (method === 'insert' && this.id == null) {
          const updatedCols = {};
          updatedCols[this.idAttribute] = this.id = resp[0];
          const updatedAttrs = this.parse(updatedCols);
          _.assign(this.attributes, updatedAttrs);
        } else if (method === 'update' && resp === 0) {
          if (options.require !== false) {
            throw new this.constructor.NoRowsUpdatedError('No Rows Updated');
          }
        }

pyldin601 avatar Aug 08 '17 17:08 pyldin601

Which version of bookshelf-camelcase are you using?

jpstone avatar Aug 08 '17 18:08 jpstone

1.1.4

pyldin601 avatar Aug 08 '17 19:08 pyldin601