-
-
Notifications
You must be signed in to change notification settings - Fork 287
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
[BUG] DynamicRef serializes to [object Object]
#1767
Comments
Hello @ochrstn I created a pr to fix this issue. But I'm not sure about the result: One thing that is strange, is about the Another things, is about the result. the id keep the _id. It's normal, because mongoose doesn't give a real class Object. and there is no metadata to retrieve the correct class according to the See you |
Thanks for looking into it.
Correct
I just tried that in the old version and (to my own surprise) it does work. |
Arff… so I don’t why it doesn’t work as expected now… |
I did some debugging and in v5.x the actual class behind the populated dynamic ref is known at this point:
and therefore can be serialized correctly |
I don't know how is it possible... Mongoose doesn't return the class behind the object: In my capture, the EventModel is here, but we see that the event instance value isn't an instance of SignedUpEventRepository, but it's an object. I haven't metadata to infer correctly the model. If it's works in v5, it was probably a mistake... |
How it works to my understanding in 5.x (not sure about my wording 😅 ): When the tsed/packages/mongoose/src/utils/createSchema.ts Lines 17 to 26 in 4db4290
Like you said, the instance obtained by mongoose isn't an instance of the class but calling Where does the |
I finally found a better way to fix that :) |
Here is the PR: using OnDeserialize and OnSerialize, it works and you retrieve the correct typings + the JSONSchema is aligned with the models declaration. I'll merge it |
Sorry for the delay @ochrstn ;) this issue wasn't easy ^^ |
🎉 This issue has been resolved in version 6.105.3 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
🎉 This issue has been resolved in version 7.0.0-beta.4 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
Information
I can at least say that it worked in
5.59.2
(thats where I upgraded from 😅 )Example
for full example, see: https://github.com/ochrstn/tsed/blob/fix-dynamicref-serialize-object/packages/orm/mongoose/test/dynamicRef.integration.spec.ts
Acceptance criteria
The text was updated successfully, but these errors were encountered: