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

Array values cannot be transformed to non-arrays #37

Open
DesignByOnyx opened this issue Jul 11, 2024 · 0 comments · May be fixed by #38
Open

Array values cannot be transformed to non-arrays #37

DesignByOnyx opened this issue Jul 11, 2024 · 0 comments · May be fixed by #38

Comments

@DesignByOnyx
Copy link

Do you want to request a feature or report a bug?

Bug - pretty much the same as #36 but with a broader scope.

What is the current behavior?

applyGetters assumes that an array will always be returned and attempts to map the returned value. We have some string arrays which return non-arrays in certain situations, and it worked with 0.4.0.

TypeError: Cannot read properties of undefined (reading 'map')
    at /mongoose-test/node_modules/mongoose-lean-getters/index.js:130:67
   ...

If the current behavior is a bug, please provide the steps to reproduce.

Here's the offending schema definition:

foo: {
  type: [String],
  get(val) => !val || !val.length ? undefined : (val.length === 1 ? val[0] : val),
  set(val) => typeof val === 'string' ? [val] : val
}

What is the expected behavior?

The above should not throw an error.

What are the versions of Node.js, mongoose-lean-getters, and Mongoose are you are using? Note that "latest" is not a version.

Node: 20.12.2
mongoose-lean-getters: 1.1.0 and 2.1.0
mongoose: 7.7.0 and 8.5.0

Note: I have a fix coming, and it will fix #36 too.

@DesignByOnyx DesignByOnyx linked a pull request Jul 11, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant