-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support createOnlyInstance in model #3548
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! Please add unit-tests to cover both regular PersistedModel create
and relation-based __create__${scopeName}
.
lib/model.js
Outdated
@@ -758,6 +758,14 @@ module.exports = function(registry) { | |||
var pathName = | |||
(scope.options && scope.options.http && scope.options.http.path) || scopeName; | |||
|
|||
var updateOnlyProps = this.getUpdateOnlyProperties(); | |||
var createOnly = false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's use a more descriptive name please, e.g. hasUpdateOnlyProps
.
Also please use const
instead of var
, see http://loopback.io/doc/en/contrib/style-guide.html#variable-declarations
const updateOnlyProps = this.getUpdateOnlyProperties();
const hasUpdateOnlyProps = updateOnlyProps && updateOnlyProps.length > 0;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment does not seem to be addressed yet?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bajtos I have two environment 1) loopback application where I can test with the API designer end to end 2) my git hub branch where I can do run tests and checkins etc. I addressed above comments in the first env to make sure I test end-to-end through API Explorer with these code review comment changes and forgot to do same change in 2nd env/local git hub branch. Tests were passing since my previous code was logically correct. Anyway, done the above change now...
lib/persisted-model.js
Outdated
@@ -627,6 +627,14 @@ module.exports = function(registry) { | |||
var typeName = PersistedModel.modelName; | |||
var options = PersistedModel.settings; | |||
|
|||
var updateOnlyProps = PersistedModel.getUpdateOnlyProperties(); | |||
var createOnly = false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto.
@bajtos PTAL
|
lib/model.js
Outdated
@@ -758,6 +758,14 @@ module.exports = function(registry) { | |||
var pathName = | |||
(scope.options && scope.options.http && scope.options.http.path) || scopeName; | |||
|
|||
var updateOnlyProps = this.getUpdateOnlyProperties(); | |||
var createOnly = false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment does not seem to be addressed yet?
test/remoting.integration.js
Outdated
@@ -316,6 +331,12 @@ function getFormattedMethodsExcludingRelations(methods) { | |||
}); | |||
} | |||
|
|||
function getCreateMethod(methods) { | |||
return methods.filter(function(m) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find it confusing that a function called getCreateMethod
returns an array of instances. Please use methods.find
instead of methods.filter
- see https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Array/find
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bajtos Done. PTAL
@slnode test please |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
@@ -316,6 +331,12 @@ function getFormattedMethodsExcludingRelations(methods) { | |||
}); | |||
} | |||
|
|||
function getCreateMethod(methods) { | |||
return methods.find(function(m) { | |||
return (m.name === 'create'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FWIW, this can be simplified to a one-liner:
return methods.find(m => m.name === 'create');
@slnode test please |
33940a4
to
7b16edd
Compare
loopback-connector-swagger failures are not related to this PR. 6 tests are failing on master branch for this connector for sometime. Opened an issue for this - strongloop/loopback-connector-swagger#45 |
This is part of solution for #2924.
Other PRs involved in the solution of issue #2924
@bajtos Work In Progress PR. Please take a initial look.
Changes include
TODO: