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
By debugging I experienced that this is not working in version 0.1.9.
I prepared the following sample code:
varmongoose=require('mongoose');varmaterializedPlugin=require('mongoose-materialized');mongoose.connect('mongodb://localhost/test');varSchema=mongoose.Schema;//Scheme inheritance setupvarShapeSchema=newSchema({name: String},{discriminatorKey: 'kind'});ShapeSchema.plugin(materializedPlugin);varShape=mongoose.model('Shape',ShapeSchema);varCircle=Shape.discriminator('Circle',newSchema({radius: Number}));varSquare=Shape.discriminator('Square',newSchema({side: Number}));varrootShape=newCircle({radius: 5});//var childShape = new Circle({radius: 5}); //-> THIS IS WORKINGvarchildShape=newSquare({side: 5});//-> NOT WORKINGrootShape.save(function(err){if(err){console.log(err);return;}rootShape.appendChild(childShape,function(err){if(err){console.log(err);return;}console.log("SUCCESS");});});
If I append childs of the same type everything is working fine.
However if I append childs of a different type (Circle -> Square in this example) I get
Error: Parent not found!
Hy everbody,
many thanks for the great work you did with this great mongoose plugin !
I want to store hierarchical data which uses mongoose schema inheritance by using Discriminators (http://mongoosejs.com/docs/discriminators.html)
By debugging I experienced that this is not working in version 0.1.9.
I prepared the following sample code:
If I append childs of the same type everything is working fine.
However if I append childs of a different type (Circle -> Square in this example) I get
Error: Parent not found!
As far as I saw using self.constructor (https://github.com/janez89/mongoose-materialized/blob/master/lib/materialized.js#L139) for the findOne(...) operation is causing this issue.
Therefore my suggestion to solve this issue would be to use the native mongodb collection instead:
Have you ever experienced this issue ?
Thanks for help
The text was updated successfully, but these errors were encountered: