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

Remove direction to include virutals in toObject #13273

Merged
merged 2 commits into from
May 16, 2023

Commits on Apr 13, 2023

  1. Remove direction to include virutals in toObject

    Passing {virtuals: true} to toObject does not have the same effect as toJSON{ vrituals: true}
    Tested on Ubuntu 22.04 and Windows 10 using version "^6.9.2"
    
    
    Can be replicated with the following model file:
    
    const postSchema = new Schema(
      {
        text: String,
        username: String,
        comments: [{ type: Schema.Types.ObjectId, ref: 'comment' }],
      },
      {
        // replace with toJSON to revert to correct behavior
        toObject: {
          virtuals: true,
        },
      }
    );
    
    // Create a virtual property `commentCount` that gets the amount of comments per post
    postSchema.virtual('commentCount').get(function () {
      return this.comments.length;
    });
    
    // Initialize our Post model
    const Post = model('post', postSchema);
    
    Please correct if I'm using this code erroneously
    iatenine committed Apr 13, 2023
    Configuration menu
    Copy the full SHA
    c81b7a8 View commit details
    Browse the repository at this point in the history

Commits on May 16, 2023

  1. Update guide.md

    vkarpov15 committed May 16, 2023
    Configuration menu
    Copy the full SHA
    4f13e99 View commit details
    Browse the repository at this point in the history