-
Notifications
You must be signed in to change notification settings - Fork 235
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
fix creation of LB4 models with auto-generated id #553
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -126,5 +126,23 @@ describe('ObjectID', function() { | |
const found = await Article.findOne({where: {title: 'abc'}}); | ||
found.xid.should.be.an.instanceOf(ds.ObjectID); | ||
}); | ||
|
||
it('handles auto-generated PK properties defined in LB4 style', async () => { | ||
const Note = ds.createModel('NoteLB4', { | ||
id: { | ||
type: 'string', | ||
id: true, | ||
generated: true, | ||
mongodb: {dataType: 'ObjectID'}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the property definition used in LB4. When the primary keys is auto-generated by the database, juggler replaces the type provided by the user ( As a result, we end up with a property defined as |
||
}, | ||
title: { | ||
type: 'string', | ||
required: true, | ||
}, | ||
}); | ||
|
||
const result = await Note.create({title: 'hello'}); | ||
// the test passes when this call does not throw | ||
}); | ||
}); | ||
}); |
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.
ObjectID
is a factory function that createsnew mongodb.ObjectID
, it's not a class. Therefore the expressionvalue instanceof ObjectID
is never true.