Typegoose对多态模型的绑定参照

时间:2018-11-28 13:21:39

标签: mongodb typescript mongoose

我遇到了多态模型

interface IEvent {
    title: string;
}
class SubscribeEvent implements IEvent {
    @prop()
    title: string;
    @prop({ref: User})
    user: IUser;
}
class NewsEvent implements IEvent {
    @prop()
    title: string;
    @prop({ref: Post})
    post: IPost;
    @prop({ref: User})
    user: IUser;
}
class OrderEvent implements IEvent {
    @prop()
    title: string;
    @prop({ref: Order})
    order: IOrder;
}

现在,我创建了一个typegoose模型:

class Card extends Typegoose {
    @prop()
    name: string;
    @prop()
    events: IEvent[];
}

如何正确映射并提取带有填充引用的Card实例?

0 个答案:

没有答案