eggjs / eggjs/egg

[Feature Request] egg-mongoose support mongoose discriminator

Open
#4,039 1 comment 2 reactions 1 assignee Claimed by @thonatos View on GitHub
Inactive
Dominant language
TypeScript
Stars
19k
Forks
1.8k
PR merge metrics
No merged PRs in 30d

Description

## Background

[Discriminators](https://mongoosejs.com/docs/discriminators.html) are a schema inheritance mechanism. They enable you to have multiple models with overlapping schemas on top of the same underlying MongoDB collection.

Current egg-mongoose use the function `loadModelToApp` to load Models to app.model. However, during loading, I can't get the base Model at another Model.

for instance, I have app/model/Event.js as a base model, and app/model/ClickedLinkEvent.js as another discriminator.

app/model/Event.js
```js
var eventSchema = new mongoose.Schema({time: Date}, options);
return mongoose.model('Event', eventSchema);
```

app/model/ClickedLinkEvent.js
```js
// I can't get the Event Model here
const { Event } = app.model;
var ClickedLinkEvent = Event.discriminator('ClickedLink',
new mongoose.Schema({url: String}, options));
```

## Proposal

find a way to support mongoose discriminator

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.