LearnBoost/mongoose — Issue #728: Nested-child DBRef Populating
Author: niftylettuce
Created: 2012-02-10 10:23:30+00:00
State: open

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

schemas/dogs.js

```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

```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

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

routes/dogs.js

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

This would in turn pull all the Sites, 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)?