Closed Rush closed 3 years ago
Updated example:
@entity.name('Drawing')
class Drawing {
@t
dimensions?: { w: number, h: number; }
constructor(@t public type: string) {}
}
@entity.name('VectorDrawing', { extends: Drawing })
class VectorDrawing extends Drawing {
@t.literal('VectorDrawing').discriminant
type!: 'VectorDrawing';
constructor(@t public svg: string) {
super('VectorDrawing');
}
}
@entity.name('RasterDrawing', { extends: Drawing })
class RasterDrawing extends Drawing {
@t.literal('RasterDrawing').discriminant
type!: 'RasterDrawing';
constructor(@t public rasterSource: string, @t public mimetype: string) {
super('RasterDrawing');
}
}
I'm going to close this since that feature was implemented.
Prior work: https://mongoosejs.com/docs/discriminators.html
Taken from a conversation on the Deepkit community Slack
What I wrote on Slack:
in deepkit code
Some design considerations
Using the example above:
Drawing
should not be aware ofRasterDrawing
orVectorDrawing
. This has the consequence of the query types againstDrawing
not be aware of fields of discriminated types.RasterDrawing
orVectorDrawing
should be done against those entities. The queries should implicitly add an appropriate filter for the discriminator key