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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: coerce property value defined as array of ObjectID #582
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,8 @@ require('./init.js'); | |
let Book, Chapter; | ||
const ds = global.getDataSource(); | ||
const objectIDLikeString = '7cd2ad46ffc580ba45d3cb1f'; | ||
const objectIDLikeString2 = '7cd2ad46ffc580ba45d3cb1e'; | ||
const promisify = require('bluebird').promisify; | ||
|
||
describe('ObjectID', function() { | ||
before(function() { | ||
|
@@ -131,11 +133,19 @@ describe('ObjectID', function() { | |
it('should properly save an array of ObjectIDs', async () => { | ||
await Article.create({ | ||
xid: objectIDLikeString, | ||
xidArr: [objectIDLikeString], | ||
xidArr: [objectIDLikeString, objectIDLikeString2], | ||
title: 'arrayOfObjectID', | ||
}); | ||
const found = await Article.findOne({where: {title: 'arrayOfObjectID'}}); | ||
found.xidArr.should.be.an.Array().which.containDeep([new ds.ObjectID(objectIDLikeString)]); | ||
const found = await Article.find({where: {title: 'arrayOfObjectID'}}); | ||
// the type of the returned array is actually string even it's stored as ObjectIds in the db as expected | ||
found[0].xidArr.should.containDeep([ | ||
new ds.ObjectID(objectIDLikeString), | ||
new ds.ObjectID(objectIDLikeString2), | ||
]); | ||
// check if the array is stored in ObjectId | ||
const raw = await findRawModelDataAsync('ArticleC', found[0].id); | ||
raw.xidArr[0].should.be.an.instanceOf(ds.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. 馃憤 |
||
raw.xidArr[1].should.be.an.instanceOf(ds.ObjectID); | ||
}); | ||
|
||
it('handles auto-generated PK properties defined in LB4 style', async () => { | ||
|
@@ -188,4 +198,8 @@ describe('ObjectID', function() { | |
found.xidArr.should.be.an.Array().which.containDeep([new ds.ObjectID(objectIDLikeString)]); | ||
}); | ||
}); | ||
function findRawModelData(modelName, id, cb) { | ||
ds.connector.execute(modelName, 'findOne', {_id: {$eq: id}}, {safe: true}, cb); | ||
} | ||
const findRawModelDataAsync = promisify(findRawModelData); | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
@agnes512 Isn't the returned
xidArr
in type objectId? From the test case, it's not string...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 am confused too. I checked with
found.xidArr[0].should.be.an.instanceOf(ds.ObjectID)
, and it fails, while thexid
test case in L129 is an objectId. I couldn't find where the array ges converted though.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.
Do you know what's the
typeof found.xidArr[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.
String!