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

populated model is not updated #129

Open
davibe opened this issue Oct 21, 2015 · 1 comment
Open

populated model is not updated #129

davibe opened this issue Oct 21, 2015 · 1 comment

Comments

@davibe
Copy link

davibe commented Oct 21, 2015

This is my model definition

schema = mongoose.Schema
  name: String
  parents: [{type: mongoose.Schema.Types.ObjectId, ref: 'Category'}]
  children: [{type: mongoose.Schema.Types.ObjectId, ref: 'Category'}]

model = mongoose.model('Category', schema)

model.formage =
  is_single: false
  list_populate: ['parents', 'children']
  search: ['parents', 'name']
  list: ['name', 'parents', 'children']

module.exports = model

I have created a "root" category and a "subcategory". The subcategory has "root" as one of its parents. If i change the name of the "root" category to "root name changed", the name is not updated in the populated models. Here are 2 sshots

name changed
screenshot 2015-10-21 11 19 37

populated values
screenshot 2015-10-21 11 19 53

@alonronin
Copy link
Contributor

you need to have toString method on the populated Schemas:

schema.methods.toString = function(){
    return this.name;
};

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

2 participants