From e8d115bdc23fcdca24a034b967e5929331ba4e10 Mon Sep 17 00:00:00 2001 From: Maxim Sharai Date: Tue, 22 Jan 2019 16:12:19 +0300 Subject: [PATCH] Fix Model.exists() to work with remote connector --- lib/persisted-model.js | 3 ++- test/util/model-tests.js | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/lib/persisted-model.js b/lib/persisted-model.js index 478fc9b6..47cd1b84 100644 --- a/lib/persisted-model.js +++ b/lib/persisted-model.js @@ -724,7 +724,8 @@ module.exports = function(registry) { description: 'Check whether a model instance exists in the data source.', accessType: 'READ', accepts: [ - {arg: 'id', type: 'any', description: 'Model id', required: true}, + {arg: 'id', type: 'any', description: 'Model id', required: true, + http: {source: 'path'}}, {arg: 'options', type: 'object', http: 'optionsFromRequest'}, ], returns: {arg: 'exists', type: 'boolean'}, diff --git a/test/util/model-tests.js b/test/util/model-tests.js index 85fc9e6b..39511d96 100644 --- a/test/util/model-tests.js +++ b/test/util/model-tests.js @@ -235,6 +235,27 @@ module.exports = function defineModelTestsWithDataSource(options) { }); }); + describe('Model.exists(id, [callback])', function() { + it('returns true when the model with the given id exists', function(done) { + User.create({first: 'max'}, function(err, user) { + if (err) return done(err); + User.exists(user.id, function(err, exist) { + if (err) return done(err); + assert.equal(exist, true); + done(); + }); + }); + }); + + it('returns false when there is no model with the given id', function(done) { + User.exists('user-id-does-not-exist', function(err, exist) { + if (err) return done(err); + assert.equal(exist, false); + done(); + }); + }); + }); + describe('Model.findById(id, callback)', function() { it('Find an instance by id', function(done) { User.create({first: 'michael', last: 'jordan', id: 23}, function() {