-
Notifications
You must be signed in to change notification settings - Fork 234
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
feat: allow methods to control strictObjectIDCoercion #467
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 work @virkt25. Can we add tests for this new behaviour?
Tried adding tests as follows in
But I keep getting the following errors:
Any idea how to add tests? There are no existing tests covering this flag / the |
@virkt25 I think you can provide the model name as string instead of a model constructor to get the tests pass: it('coerces ObjectID', function() {
// note it is 'Book' not Book
const coercedId = db.connector.coerceId('Book', '52fcef5c0325ace8dcb7a0bd');
coercedId.should.be.an.instanceOf(db.ObjectID);
}); |
Here is the code throwing the error (assuming your stack trace is from the latest version of loopback-connector as seen on GitHub): Connector.prototype.idName = function(model) {
return this.getDataSource(model).idName(model);
}; I strongly suspect that in the test you tried to wrote, there was no model defined on the datasource with the name matching the string you passed to What you need to do in your test:
it('coerces ObjectID', function() {
const Book = db.createModel('Book' /*, {properties...}, {settings...}*/);
const coercedId = db.connector.coerceId(Book.modelName, '52fcef5c0325ace8dcb7a0bd');
coercedId.should.be.an.instanceOf(db.ObjectID);
}); I am typing this information from my head, it may not be entirely accurate. Sorry if it does not work out of the box! |
Signed-off-by: virkt25 <taranveer@virk.cc>
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! LGTM
Description
loopback4-example-shopping
. For relations, we need to be able to enablestrictObjectIDCoercion
for those methods only. This PR allows the flag to be passed in from a method instead of just being set on the model.Related issues
Checklist
guide