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

[IDEA] Support local and remote field selection in Schema #9868

Closed
scucchiero opened this issue Jan 26, 2021 · 1 comment
Closed

[IDEA] Support local and remote field selection in Schema #9868

scucchiero opened this issue Jan 26, 2021 · 1 comment
Labels
help This issue can likely be resolved in GitHub issues. No bug fixes, features, or docs necessary

Comments

@scucchiero
Copy link

scucchiero commented Jan 26, 2021

When marking a field as selected: false you can't access it (obviously) because is not fetched.
I ran into this use case tho and thought could be a good idea to expand the functionally of select to enable fetch but remove the key after constructing the model. Thus, enabling the following.

const MySchema = new Schema(
  {
    username: {
      type: String,
      required: true,
    },
    password: {
      type: String,

     // this is the proposal
      select: {
          virtual: true
       }
    }
  },
  {
    toJSON: {  virtuals: true },
    toObject: { virtuals: true },
  },
);

ShowSchema.virtual("hasPassword").get(function() {
  return !!this.password
 })

Thoughts?

@vkarpov15
Copy link
Collaborator

The issue here is that you're trying to load password, but make sure password doesn't end up getting sent to the user. That's what transforms are for.

Also, storing password on a user document is generally an antipattern: https://thecodebarbarian.com/thoughts-on-user-passwords-in-rest-apis

@vkarpov15 vkarpov15 added the help This issue can likely be resolved in GitHub issues. No bug fixes, features, or docs necessary label Jan 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help This issue can likely be resolved in GitHub issues. No bug fixes, features, or docs necessary
Projects
None yet
Development

No branches or pull requests

2 participants