You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Do you want to request a feature or report a bug?
Report a bug. What is the current behavior?
See comments on two last lines of code - getter is skipped when calling toJSON on parent, despite having "getters: true" on all schemas. If the current behavior is a bug, please provide the steps to reproduce.
var { model, Schema } = require('mongoose');
var childSchema = new Schema({}, {
toJSON: { getters: true }
});
childSchema.virtual('field')
.get(function(){
return this._field;
})
.set(function(v){
return this._field = v;
});
var Child = model('Child', childSchema);
var parentSchema = new Schema({
child: { type: Schema.Types.ObjectId, ref: 'Child', get: childGetter }
}, {
toJSON: { getters: true }
});
function childGetter(child){
child.field = true;
return child;
}
var Parent = model('Parent', parentSchema);
//=====================
var child = new Child();
var parent = new Parent({ child });
console.log(parent.toJSON().child.field); //prints 'undefined'
console.log(parent.child.toJSON().field); //prints 'true'
What is the expected behavior?
To have "true" as output of both console.logs. What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version.
Node.js 8.9.3
Mongoose 5.6.0
MongoDB irrelevant - MWE does not connect to DB at all
The text was updated successfully, but these errors were encountered:
vkarpov15
added
has repro script
There is a repro script, the Mongoose devs need to confirm that it reproduces the issue
confirmed-bug
We've confirmed this is a bug in Mongoose and will fix it.
and removed
has repro script
There is a repro script, the Mongoose devs need to confirm that it reproduces the issue
labels
Nov 6, 2019
Confirmed this is a bug, looks related to the work from #7442. I tried a few different ways to fix it, but having some trouble getting the tests for this issue, #7442, and #1376 to pass at the same time. Will try again later 👍
Do you want to request a feature or report a bug?
Report a bug.
What is the current behavior?
See comments on two last lines of code - getter is skipped when calling toJSON on parent, despite having "getters: true" on all schemas.
If the current behavior is a bug, please provide the steps to reproduce.
What is the expected behavior?
To have "true" as output of both
console.log
s.What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version.
Node.js 8.9.3
Mongoose 5.6.0
MongoDB irrelevant - MWE does not connect to DB at all
The text was updated successfully, but these errors were encountered: