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

Enum support on array of array #7926

Closed
Mangosteen-Yang opened this issue Jun 25, 2019 · 4 comments
Closed

Enum support on array of array #7926

Mangosteen-Yang opened this issue Jun 25, 2019 · 4 comments
Labels
enhancement This issue is a user-facing general improvement that doesn't fix a bug or add a new feature
Milestone

Comments

@Mangosteen-Yang
Copy link
Contributor

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

What is the current behavior?

  people: {
    type: [[String]],
    enum: [
      'manager',
      'student',
      'account',
    ],
  },

Throw an Error:
Error: enum can only be set on an array of strings, not Array

What is the expected behavior?
check each string like array of string

What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version.
Node 12.0
Mongoose 5.6.1
MongoDB 4.1.0

@vkarpov15 vkarpov15 added this to the 5.x Unprioritized milestone Jun 25, 2019
@vkarpov15 vkarpov15 added the developer-experience This issue improves error messages, debugging, or reporting label Jun 25, 2019
@vkarpov15
Copy link
Collaborator

As a workaround, you can do:

  people: {
    type: [[{ type: String, enum: ['manager', 'student'] }]]
  },

@vkarpov15 vkarpov15 added enhancement This issue is a user-facing general improvement that doesn't fix a bug or add a new feature and removed developer-experience This issue improves error messages, debugging, or reporting labels Jun 25, 2019
@vkarpov15 vkarpov15 modified the milestones: 5.x Unprioritized, 5.6.7 Jul 21, 2019
@vkarpov15
Copy link
Collaborator

This ended up being much trickier than I thought because my workaround from my original comment doesn't actually work right now. Looks like validators on nested arrays were broken. We'll need to prioritize some refactoring work on nested arrays like #6405

@Mangosteen-Yang
Copy link
Contributor Author

Mangosteen-Yang commented Jul 24, 2019

This ended up being much trickier than I thought because my workaround from my original comment doesn't actually work right now. Looks like validators on nested arrays were broken. We'll need to prioritize some refactoring work on nested arrays like #6405

Thanks for updating. I will write a pre middleware to check enum before fix/release.
I guess I can use type: [[String]] on 5.6.7 right?

@vkarpov15
Copy link
Collaborator

Yep, once 5.6.7 is released 👍

@Automattic Automattic locked as resolved and limited conversation to collaborators Jul 29, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement This issue is a user-facing general improvement that doesn't fix a bug or add a new feature
Projects
None yet
Development

No branches or pull requests

2 participants