-
-
Notifications
You must be signed in to change notification settings - Fork 286
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(mongoose): Fix json schema for VirtualRef
if MongooseModels entry not set yet
#1672
Conversation
Benchmark resulttsed vs express: New benchmarks generated
Details:
|
@ochrstn Maybe we can wrap the ref in arrow function instead ? but the first step is a to add a unit or integration test that show the problem + expectation. Then we can find a solution. See you |
Benchmark resulttsed vs express: New benchmarks generated
Details:
|
I added a failing test. I also tried to change the function getType(opts: any) {
const ref = opts.ref || opts.type;
return isString(ref) ? MongooseModels.get(ref) || Object : isArrowFn(ref) ? ref() : ref;
}
export function VirtualRef(options: string | MongooseVirtualRefOptions, foreignField?: string): Function {
const opts = getInitialOpts(options, foreignField);
const schema = mapToSchema(opts);
return useDecorators(
StoreMerge(MONGOOSE_SCHEMA, schema),
JsonEntityFn((store) => {
store.itemSchema.type(schema.count ? Number : lazyRef(getType(opts)));
store.type = Object;
})
);
} But that results |
8b1a306
to
102de16
Compare
Fixed :) |
Benchmark resulttsed vs express: New benchmarks generated
Details:
|
🎉 This PR is included in version 6.95.1 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
…ry not set yet (#1672) * fix(mongoose): Fix json schema for `VirtualRef` if MongooseModels entry not set yet * fix(mongoose): Wrap type into an arrow function to lazy load the model
Information
Sadly my last fix (#1670) introduced a new bug.
MongooseModels.get(ref)
can return undefined and the property doesn't even get serialized. With the fallback toObject
it would behave like before.That happens a lot in my project because
tsed/packages/orm/mongoose/src/utils/createModel.ts
Line 11 in 3e6cece
tsed/packages/orm/mongoose/src/decorators/virtualRef.ts
Line 16 in 3e6cece
@Romakita any idea on how to fix the order problem?
Todos