Merge tag 'v3.16.1'

Bring in changes from #3674 that were accidentally not landed on master:

 * Fix createOnlyInstance for related methods (Raymond Feng)

Close #3674
This commit is contained in:
Miroslav Bajtoš 2017-10-30 09:00:16 +01:00
commit 825d5a6373
No known key found for this signature in database
GPG Key ID: 6F2304BA9361C7E3
4 changed files with 27 additions and 9 deletions

View File

@ -1,3 +1,9 @@
2017-10-28, Version 3.16.1
==========================
* Fix createOnlyInstance for related methods (Raymond Feng)
2017-10-24, Version 3.16.0
==========================

View File

@ -763,12 +763,7 @@ module.exports = function(registry) {
var pathName =
(scope.options && scope.options.http && scope.options.http.path) || scopeName;
// if there is atleast one updateOnly property, then we set
// createOnlyInstance flag in __create__ to indicate loopback-swagger
// code to create a separate model instance for create operation only
const updateOnlyProps = this.getUpdateOnlyProperties ?
this.getUpdateOnlyProperties() : false;
const hasUpdateOnlyProps = updateOnlyProps && updateOnlyProps.length > 0;
var modelTo = scope.modelTo;
var isStatic = scope.isStatic;
var toModelName = scope.modelTo.modelName;
@ -780,8 +775,16 @@ module.exports = function(registry) {
// For a relation with through model, the toModelName should be the one
// from the target model
toModelName = relation.modelTo.modelName;
modelTo = relation.modelTo;
}
// if there is atleast one updateOnly property, then we set
// createOnlyInstance flag in __create__ to indicate loopback-swagger
// code to create a separate model instance for create operation only
const updateOnlyProps = modelTo.getUpdateOnlyProperties ?
modelTo.getUpdateOnlyProperties() : false;
const hasUpdateOnlyProps = updateOnlyProps && updateOnlyProps.length > 0;
define('__get__' + scopeName, {
isStatic: isStatic,
http: {verb: 'get', path: '/' + pathName},

View File

@ -1,6 +1,6 @@
{
"name": "loopback",
"version": "3.16.0",
"version": "3.16.1",
"description": "LoopBack: Open Source Framework for Node.js",
"homepage": "http://loopback.io",
"keywords": [

View File

@ -133,8 +133,8 @@ describe('remoting - integration', function() {
it('should have correct signatures for hasMany methods',
function() {
var physicianClass = findClass('store');
var methods = getFormattedPrototypeMethods(physicianClass.methods);
var storeClass = findClass('store');
var methods = getFormattedPrototypeMethods(storeClass.methods);
var expectedMethods = [
'prototype.__findById__widgets(fk:any):widget ' +
@ -208,6 +208,15 @@ describe('remoting - integration', function() {
var createMethod = getCreateMethod(customerClass.methods);
assert(createMethod.accepts[0].createOnlyInstance === false);
});
it('sets createOnlyInstance based on target model for scoped or related methods',
function() {
var userClass = findClass('user');
var createMethod = userClass.methods.find(function(m) {
return (m.name === 'prototype.__create__accessTokens');
});
assert(createMethod.accepts[0].createOnlyInstance === false);
});
});
});