diff --git a/lib/read-only.js b/lib/read-only.js index 15d6ea1..ed9e438 100644 --- a/lib/read-only.js +++ b/lib/read-only.js @@ -33,7 +33,7 @@ module.exports = Model => { const AffectedModel = Model.app.loopback.getModel(modelName) const options = AffectedModel.settings.mixins.ReadOnly const properties = (Object.keys(options).length) ? options : null - const instanceId = ctx.args[AffectedModel.getIdName()] + const instanceId = ctx.args[AffectedModel.getIdName()] || body.id if (properties) { debug('Found read only properties for model %s: %o', modelName, properties) diff --git a/test/test.js b/test/test.js index 2db2066..7956f39 100644 --- a/test/test.js +++ b/test/test.js @@ -153,7 +153,7 @@ describe('loopback datasource readonly property (mixin sources.js)', function() .send({ id: this.product.id, status: 'disabled' }) .expect(200) .then(() => app.models.Product.findById(this.product.id)) - .then(product => expect(product.status).to.equal('temp')) + .then(product => expect(product.status).to.equal('pending')) }) }) @@ -186,7 +186,7 @@ describe('loopback datasource readonly property (mixin sources.js)', function() .send(Object.assign(this.product.toJSON(), { status: 'disabled' })) .expect(200) .then(() => app.models.Product.findById(this.product.id)) - .then(product => expect(product.status).to.equal('temp')) + .then(product => expect(product.status).to.equal('pending')) }) })