Skip to content
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

Using discriminators #31

Open
esimonm opened this issue Aug 29, 2022 · 5 comments
Open

Using discriminators #31

esimonm opened this issue Aug 29, 2022 · 5 comments
Labels
enhancement New feature or request

Comments

@esimonm
Copy link

esimonm commented Aug 29, 2022

Hi @sandeepsuvit, I hope you are doing well. First, thanks for developing this, I've found it super helpful and so easy to apply!

I wonder if it'd be possible for us to apply discriminators the same way as Nest currently does (please see the application in https://docs.nestjs.com/techniques/mongodb#discriminators). Currently, there is no way to declare the discriminators in the module's imports, as it throws a type error as the discriminators field is not declared in the ModelDefinition interface you created.

This would be a great addition to our current projects.

Again, thanks for all your effort, looking forward to your reply!

@sandeepsuvit
Copy link
Contributor

Hi @esimonm thanks for the feedback. Regarding you query on discriminators i don't think the library does a hard type check against this. However this check can come from the underlying dependency types of mongoose that are being used is what my guess is. If you think otherwise can you point me to the line in the code where this is happening with a sample code so that i can debug it further.

@esimonm
Copy link
Author

esimonm commented Aug 30, 2022

Thanks for the quick reply @sandeepsuvit, really appreciate it. Please see the following error I'm getting when declaring the discriminators on the module's TenancyModule.forFeature as shown in Nest's documentation.

image

And here is the ModelDefinition interface:

image

Let me know if you need any more info, thanks!

@sandeepsuvit
Copy link
Contributor

sandeepsuvit commented Aug 30, 2022

Hi @esimonm thanks for pointing it out. I haven't used discriminators with nestjs before so i am not familiar with its functionality. I have made the changes referring to nestjs/mongoose wrapper implementation. The changes are available under the following branch. Please check it out and let me know if its working for you. If it does, then ill release a new version with these changes.

@sandeepsuvit sandeepsuvit added the enhancement New feature or request label Aug 30, 2022
@esimonm
Copy link
Author

esimonm commented Aug 30, 2022

Thanks for the quick update! Tried it and there are no longer any type errors, but unfortunately, it's still giving an error when compiling as shown here:

image

"Issue" is the Entity the module is based on. Two other entities are used in the discriminator array. Seems like the Tenancy module is not importing the Issue module?

Please let me know if there's any more info needed. Thanks again.

@sandeepsuvit
Copy link
Contributor

@esimonm can you provide me a minimal example working sample repo to test this out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants