bookshelf-modelbase
Advanced tools
Comparing version 2.9.0 to 2.10.0
@@ -50,2 +50,4 @@ var extend = require('xtend') | ||
if (validation.error) { | ||
validation.error.tableName = this.tableName | ||
throw validation.error | ||
@@ -70,2 +72,12 @@ } else { | ||
/** | ||
* Find a model based on it's ID | ||
* @param {String} id The model's ID | ||
* @param {Object} [options] Options used of model.fetch | ||
* @return {Promise(bookshelf.Model)} | ||
*/ | ||
findById: function (id, options) { | ||
return this.findOne({ [this.prototype.idAttribute]: id }, options) | ||
}, | ||
/** | ||
* Select a model based on a query | ||
@@ -72,0 +84,0 @@ * @param {Object} [query] |
{ | ||
"name": "bookshelf-modelbase", | ||
"version": "2.9.0", | ||
"version": "2.10.0", | ||
"description": "Extensible ModelBase for bookshelf-based model layers", | ||
@@ -5,0 +5,0 @@ "main": "./lib", |
@@ -112,2 +112,16 @@ # bookshelf-modelbase | ||
### model.findById | ||
```javascript | ||
/** | ||
* Find a model based on it's ID | ||
* @param {String} id The model's ID | ||
* @param {Object} [options] Options used of model.fetch | ||
* @return {Promise(bookshelf.Model)} | ||
*/ | ||
findById: function (id, options) { | ||
return this.findOne({ [this.prototype.idAttribute]: id }, options) | ||
} | ||
``` | ||
#### model.findOne | ||
@@ -114,0 +128,0 @@ |
@@ -90,6 +90,12 @@ /* global describe, before, after, beforeEach, it */ | ||
it('should error on invalid attributes', function () { | ||
var error | ||
specimen.set('first_name', 1) | ||
expect(function () { | ||
try { | ||
specimen.validateSave() | ||
}).to.throw(/first_name must be a string/) | ||
} catch (err) { | ||
error = err | ||
} | ||
expect(error.tableName).to.equal('test_table') | ||
}) | ||
@@ -140,2 +146,16 @@ | ||
describe('findById', function () { | ||
it('should find a model by it\'s id', function () { | ||
var created | ||
return SpecimenClass.create({ first_name: 'yo' }) | ||
.then(function (model) { | ||
created = model | ||
return SpecimenClass.findById(model.id) | ||
}) | ||
.then(function (model) { | ||
expect(model.id).to.deep.equal(created.id) | ||
}) | ||
}) | ||
}) | ||
describe('findOne', function () { | ||
@@ -142,0 +162,0 @@ it('should return a model', function () { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
23627
471
179