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:
commit
825d5a6373
|
@ -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
|
2017-10-24, Version 3.16.0
|
||||||
==========================
|
==========================
|
||||||
|
|
||||||
|
|
15
lib/model.js
15
lib/model.js
|
@ -763,12 +763,7 @@ module.exports = function(registry) {
|
||||||
var pathName =
|
var pathName =
|
||||||
(scope.options && scope.options.http && scope.options.http.path) || scopeName;
|
(scope.options && scope.options.http && scope.options.http.path) || scopeName;
|
||||||
|
|
||||||
// if there is atleast one updateOnly property, then we set
|
var modelTo = scope.modelTo;
|
||||||
// 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 isStatic = scope.isStatic;
|
var isStatic = scope.isStatic;
|
||||||
var toModelName = scope.modelTo.modelName;
|
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
|
// For a relation with through model, the toModelName should be the one
|
||||||
// from the target model
|
// from the target model
|
||||||
toModelName = relation.modelTo.modelName;
|
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, {
|
define('__get__' + scopeName, {
|
||||||
isStatic: isStatic,
|
isStatic: isStatic,
|
||||||
http: {verb: 'get', path: '/' + pathName},
|
http: {verb: 'get', path: '/' + pathName},
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "loopback",
|
"name": "loopback",
|
||||||
"version": "3.16.0",
|
"version": "3.16.1",
|
||||||
"description": "LoopBack: Open Source Framework for Node.js",
|
"description": "LoopBack: Open Source Framework for Node.js",
|
||||||
"homepage": "http://loopback.io",
|
"homepage": "http://loopback.io",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
|
|
|
@ -133,8 +133,8 @@ describe('remoting - integration', function() {
|
||||||
|
|
||||||
it('should have correct signatures for hasMany methods',
|
it('should have correct signatures for hasMany methods',
|
||||||
function() {
|
function() {
|
||||||
var physicianClass = findClass('store');
|
var storeClass = findClass('store');
|
||||||
var methods = getFormattedPrototypeMethods(physicianClass.methods);
|
var methods = getFormattedPrototypeMethods(storeClass.methods);
|
||||||
|
|
||||||
var expectedMethods = [
|
var expectedMethods = [
|
||||||
'prototype.__findById__widgets(fk:any):widget ' +
|
'prototype.__findById__widgets(fk:any):widget ' +
|
||||||
|
@ -208,6 +208,15 @@ describe('remoting - integration', function() {
|
||||||
var createMethod = getCreateMethod(customerClass.methods);
|
var createMethod = getCreateMethod(customerClass.methods);
|
||||||
assert(createMethod.accepts[0].createOnlyInstance === false);
|
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);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue