-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
Discriminator - reUse #10931
Labels
new feature
This change adds new functionality, like a new method or class
Milestone
Comments
Hello @cacothi Please provide full code example to reproduce. |
Never mind, i made it work based on other exposed properties. Just opened
this ticket to help the library, but can’t share the code as it’s not a
single file. As mentioned, I create the models dynamically to have a
flexible prefixed collection name
On Tue, 26 Oct 2021 at 4:38 pm, Kamikadze4GAME ***@***.***> wrote:
Hello @cacothi <https://github.com/cacothi>
Please provide full code example to reproduce.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#10931 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AC4AGT7SNZ7CMOXQKA2GBATUIZLHBANCNFSM5GWU77AA>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
--
Sent from iPhone
|
So the problem still exists but you found a workaround? |
IslandRhythms
added
the
needs clarification
This issue doesn't have enough information to be actionable. Close after 14 days of inactivity
label
Oct 26, 2021
Yes. The problem is when you retrieve the schema using discriminator.
I opened the code and it add the discriminator to a property
model.discriminators[name].
When I invoke the same method for the second time I get the message above.
The work around is to check on my code if model.discriminators[name] exists
and retrieve it.
However, this is a work around as JavaScript do not protect that variable,
and it’s just exposed due the lack of protection in the class.
I would expect to , or have a flag to reuse an already instantiate
discriminator, or jus retrieve if it already exists, same way I’m doing it.
I can create a pull request with the solution that I found for analysis.
On Wed, 27 Oct 2021 at 2:28 am, Daniel Diaz ***@***.***> wrote:
So the problem still exists but you found a workaround?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#10931 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AC4AGT6P6IQJKRLHSUD5ED3UI3JJBANCNFSM5GWU77AA>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
--
Sent from iPhone
|
@cacothi sure, a flag for this would be useful. If you can put in a PR with this behavior behind a flag, that would be most appreciated 👍 |
vkarpov15
added
new feature
This change adds new functionality, like a new method or class
and removed
needs clarification
This issue doesn't have enough information to be actionable. Close after 14 days of inactivity
labels
Oct 30, 2021
vkarpov15
added a commit
that referenced
this issue
Jan 24, 2022
Gh 10931 - `overwriteModels:true` to reuse discriminators
2 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Do you want to request a feature or report a bug?
Bug (?!)
What is the current behavior?
When using model.discriminator(name, schema), I get the following error when running by the second time:
Error('Discriminator with name "' + name + '" already exists');
The issue is that my code make references of schema and models dynamically, and when I try to refer a model that already contain that discriminator I get this error.
If the current behavior is a bug, please provide the steps to reproduce.
My framework is quite complex to share here, but as mentioned, I have all schemas defined, but the models are instantiated dynamically as the collection name changes depending on the request.
no typescript
What is the expected behavior?
The expected behavior is to return the discriminator that already exists. My work around was accessing the model.discriminators property to check if that specifc discriminator already exist:
What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version.
"mongoose": "^6.0.12",
Node: 16
MongoDB: 5.x
The text was updated successfully, but these errors were encountered: