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

Updating nested keywords only works when we save the object with the nested object populated with keywords #32

Open
sbland opened this issue Feb 14, 2022 · 0 comments

Comments

@sbland
Copy link

sbland commented Feb 14, 2022

If we save a object without populating the nested objects we lose the nested keywords. The modified example below shows the issue.

  var mongoose = require('mongoose');
  var mongooseKeywords = require('mongoose-keywords');

  var GenreSchema = new mongoose.Schema({
    title: String
  });
  GenreSchema.plugin(mongooseKeywords, {paths: ['title']});

  var ArtistSchema = new mongoose.Schema({
    name: String,
    genre: {
      type: mongoose.Schema.ObjectId,
      ref: 'Genre'
    }
  });
  ArtistSchema.plugin(mongooseKeywords, {paths: ['name', 'genre']});

  var Genre = mongoose.model('Genre', GenreSchema);
  var genre = new Genre({title: 'Jrock'});
  console.info(genre.keywords); // ['jrock']

  var Artist = mongoose.model('Artist', ArtistSchema);
  var artist = new Artist({name: "L'arc~en~Ciel", genre: genre._id}); /* genre saved as object id */
  console.info(artist.keywords); // ['larc en ciel', 'jrock']
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

No branches or pull requests

1 participant