diff --git a/lib/computed.js b/lib/computed.js index c1b2e45..34f6494 100644 --- a/lib/computed.js +++ b/lib/computed.js @@ -26,6 +26,11 @@ module.exports = (Model, options) => { return next() } + // Skip if specified in options + if (ctx.options.skipComputed) { + return next() + } + return Promise.map(Object.keys(options.properties), property => { const callback = options.properties[property] diff --git a/test/test.js b/test/test.js index 7ea5e6b..b90e9e5 100644 --- a/test/test.js +++ b/test/test.js @@ -106,4 +106,15 @@ describe('loopback computed property', function() { expect(itemFromDb).to.not.have.property('promised') }) }) + + it('should not compute if requested with "skipComputed" attribute', function() { + const { id } = this.itemOne + + return new Promise(function(res) { + Item.find({ where: { id } }, { skipComputed: true }).then(function(item) { + expect(typeof item[0].readonly).to.be.equal('undefined') + res() + }) + }) + }) })