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

Nested-child DBRef Populating #728

Closed
niftylettuce opened this issue Feb 10, 2012 · 1 comment
Closed

Nested-child DBRef Populating #728

niftylettuce opened this issue Feb 10, 2012 · 1 comment

Comments

@niftylettuce
Copy link
Contributor

Could we support recursive nested-child DBRef population? For example:

schemas/dogs.js

module.exports = function(db) {
  var Dogs = new db.Schema({
    name: String,
    _breed: {
      type: db.Schema.ObjectId,
      ref: 'Breeds'
    }
  });
  return db.model('Dogs', Dogs);
};

schemas/breeds.js

module.exports = function(db) {
  var Breeds = new db.Schema({
    name: String,
    _fur: {
      type: db.Schema.ObjectId,
      ref: 'Furs'
    }
  });
  return db.model('Breeds', Breeds);
}

schemas/furs.js

module.exports = function(db) {
  var Furs = new db.Schema({
    color: String
  });
  return db.model('Furs', Furs);
}

routes/dogs.js

var Dogs = db.model('Dogs');
Dogs
  .find()
  .populate('_breed._fur')
  .run(function(err, dog) {
    if (err) throw err;
    console.log(dog);
    res.json(dog);
  });

This would in turn pull all the Dogs, then populate their _breed's, and populate each _breed's _fur's.

Also, what is the general view about pluralize vs. singular? Should we have singular db schema names etc.?
-- I thought there was a pluralize function that automatically did this or something (if I can remember correctly)?

@aheckmann
Copy link
Collaborator

closing this. tracking it in #601

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