Skip to content

Commit e8d115b

Browse files
angfalbajtos
authored andcommittedMay 13, 2019
Fix Model.exists() to work with remote connector
1 parent ae3fff9 commit e8d115b

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed
 

‎lib/persisted-model.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -724,7 +724,8 @@ module.exports = function(registry) {
724724
description: 'Check whether a model instance exists in the data source.',
725725
accessType: 'READ',
726726
accepts: [
727-
{arg: 'id', type: 'any', description: 'Model id', required: true},
727+
{arg: 'id', type: 'any', description: 'Model id', required: true,
728+
http: {source: 'path'}},
728729
{arg: 'options', type: 'object', http: 'optionsFromRequest'},
729730
],
730731
returns: {arg: 'exists', type: 'boolean'},

‎test/util/model-tests.js

+21
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,27 @@ module.exports = function defineModelTestsWithDataSource(options) {
235235
});
236236
});
237237

238+
describe('Model.exists(id, [callback])', function() {
239+
it('returns true when the model with the given id exists', function(done) {
240+
User.create({first: 'max'}, function(err, user) {
241+
if (err) return done(err);
242+
User.exists(user.id, function(err, exist) {
243+
if (err) return done(err);
244+
assert.equal(exist, true);
245+
done();
246+
});
247+
});
248+
});
249+
250+
it('returns false when there is no model with the given id', function(done) {
251+
User.exists('user-id-does-not-exist', function(err, exist) {
252+
if (err) return done(err);
253+
assert.equal(exist, false);
254+
done();
255+
});
256+
});
257+
});
258+
238259
describe('Model.findById(id, callback)', function() {
239260
it('Find an instance by id', function(done) {
240261
User.create({first: 'michael', last: 'jordan', id: 23}, function() {

0 commit comments

Comments
 (0)
Please sign in to comment.