diff --git a/lib/scope.js b/lib/scope.js index da8aa1ad..ac14efc7 100644 --- a/lib/scope.js +++ b/lib/scope.js @@ -1,3 +1,4 @@ +var i8n = require('inflection'); var utils = require('./utils'); var defineCachedRelations = utils.defineCachedRelations; /** @@ -83,6 +84,10 @@ function defineScope(cls, targetClass, name, params, methods) { } }; f._scope = typeof params === 'function' ? params.call(this) : params; + f._targetClass = targetClass.modelName; + if (f._scope.collect) { + f._targetClass = i8n.capitalize(f._scope.collect); + } f.build = build; f.create = create; @@ -116,7 +121,7 @@ function defineScope(cls, targetClass, name, params, methods) { fn.shared = true; fn.http = {verb: 'get', path: '/' + name}; fn.accepts = {arg: 'filter', type: 'object'}; - fn.description = 'Fetches ' + name; + fn.description = 'Queries ' + name + ' of this model.'; fn.returns = {arg: name, type: 'array', root: true}; cls['__get__' + name] = fn; @@ -129,7 +134,7 @@ function defineScope(cls, targetClass, name, params, methods) { fn_create.shared = true; fn_create.http = {verb: 'post', path: '/' + name}; fn_create.accepts = {arg: 'data', type: 'object', http: {source: 'body'}}; - fn_create.description = 'Creates ' + name; + fn_create.description = 'Creates a new instance in ' + name + ' of this model.'; fn_create.returns = {arg: 'data', type: 'object', root: true}; cls['__create__' + name] = fn_create; @@ -140,7 +145,7 @@ function defineScope(cls, targetClass, name, params, methods) { }; fn_delete.shared = true; fn_delete.http = {verb: 'delete', path: '/' + name}; - fn_delete.description = 'Deletes ' + name; + fn_delete.description = 'Deletes all ' + name + ' of this model.'; fn_delete.returns = {arg: 'data', type: 'object', root: true}; cls['__delete__' + name] = fn_delete; diff --git a/package.json b/package.json index d869d38a..36a37987 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "loopback-datasource-juggler", - "version": "1.3.8", + "version": "1.3.9", "description": "LoopBack DataSoure Juggler", "keywords": [ "StrongLoop", diff --git a/test/relations.test.js b/test/relations.test.js index 9955ada7..7bc3a1b3 100644 --- a/test/relations.test.js +++ b/test/relations.test.js @@ -68,7 +68,7 @@ describe('relations', function () { }); }); - it.skip('should fetch all scoped instances', function (done) { + it('should fetch all scoped instances', function (done) { Book.create(function (err, book) { book.chapters.create({name: 'a'}, function () { book.chapters.create({name: 'z'}, function () { @@ -117,6 +117,10 @@ describe('relations', function () { }); } }); + + it('should set targetClass on scope property', function() { + should.equal(Book.prototype.chapters._targetClass, 'Chapter'); + }); }); describe('belongsTo', function () { @@ -248,6 +252,9 @@ describe('relations', function () { }); }); + it('should set targetClass on scope property', function() { + should.equal(Article.prototype.tags._targetClass, 'Tag'); + }); }); });