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

Unexpected ref function behaviour #1847

Closed
1 of 4 tasks
piyushk96 opened this issue Jul 4, 2023 · 1 comment
Closed
1 of 4 tasks

Unexpected ref function behaviour #1847

piyushk96 opened this issue Jul 4, 2023 · 1 comment
Labels

Comments

@piyushk96
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

Current behavior

ref function passed in schema options is being overridden by the static return value of that function during schema initialization.

Minimum reproduction code

https://codesandbox.io/p/sandbox/confident-antonelli-m7js5d

Steps to reproduce

No response

Expected behavior

According to Mongoose documentation ref function should be called for every populate() call to determine the field's model according to the current document dynamically.

But in the current scenario, the ref is called only once during initialization and uses that fixed return value for the rest of populate calls.

Package version

10.0.0

mongoose version

7.3.1

NestJS version

No response

Node.js version

16

In which operating systems have you tested?

  • macOS
  • Windows
  • Linux

Other

const result = (optionsOrType.ref as Function)();
optionsOrType.ref = result?.name ?? result;

ref in schema options is being overridden here

@piyushk96 piyushk96 added the bug label Jul 4, 2023
@kamilmysliwiec
Copy link
Member

Please, use our Discord channel (support) for such questions. We are using GitHub to track bugs, feature requests, and potential improvements.

@nestjs nestjs locked and limited conversation to collaborators Jul 4, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants