Closed JanKaczmarkiewicz closed 3 years ago
We did some work to support embedded discriminators, but we're gonna have to do some more work to support multidimensional arrays. Thanks for your patience :+1:
Fix will be in 0.13.0 and require Mongoose >= 5.12.4. Below is the syntax:
const enemySchema = new Schema({
name: String,
level: Number
});
const Enemy = db.model('Enemy', enemySchema);
const mapSchema = new Schema({
tiles: [[new Schema({}, { discriminatorKey: 'kind', _id: false })]]
});
const contentPath = mapSchema.path('tiles');
contentPath.discriminator('Enemy', new Schema({
enemy: { type: Schema.Types.ObjectId, ref: 'Enemy', autopopulate: true }
}));
contentPath.discriminator('Wall', new Schema({ color: String }));
mapSchema.plugin(autopopulate);
@vkarpov15 Thank You very much <3
Feature request It is possible to auto populate 2d array field containing discriminated schema?:
What is the expected behaviour? The discriminated field in arrays are auto-populated during queries
What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version. mongoose: 5.11.14 mongoose-autopopulate: 0.12.3 node: 15.7.0