LearnBoost/mongoose — pull request #2235 by chetverikov (2014-08-07 07:30:40+00:00)
Title: Dynamical ref link

This pull-request provides the ability to use dynamic ref links.

# Use guide

Add refPath in schema (for one field must be used or ref or refPath options):

```javascript

ArrayPopulate = new Schema({
items: [{
// here add refPath option
item: { type: mongoose.SchemaTypes.Mixed, refPath: 'items.type' },
// here contains model name
type: { type: String }
}]
})
mongoose.model('ap', ArrayPopulate);
```
refPath contains the path to the field where to store the model name.
Example data:

```javascript
var ap = mongoose.model('ap');
ap.create({
items: [
{item: 32, type: 'DynRefReview'},
{item: 12, type: 'DynRefPlace'},
{item: 21, type: 'DynRefNote'}
]
}, function(){
ap.find({}).populate('items.item').exec(function(err, aps){
/**
will contain:
aps = {
items:[
{ item: { here_DynRefReview_object }, type: 'DynRefReview'},
{ item: { here_DynRefPlace_object }, type: 'DynRefPlace'},
{ item: { here_DynRefNote_object }, type: 'DynRefNote'},
]
}
*/
})
})
```