LearnBoost/mongoose — Issue #597: DBRef's not returning virtuals when explicitly set
Author: ded
Created: 2011-11-07 00:37:25+00:00
State: open

Hi there. We ran into an issue (unsure if it's known or not) on accessing virtuals when returned from DBRefs.

Given this code

``` js

var schema = new Schema({
name: {
first: String
, last: String
}
})

schema
.virtual('fullname')
.get(function () {
return [this.name.first, this.name.last].join(' ')
})

var UserModel = mongoose.model('Users', schema)

var GroupModel = mongoose.model('Groups', new Schema({
name: String
, users: { type: [Schema.ObjectId], ref: 'Users' }
})
```

You could access the first full name in the set as such:

``` js
GroupModel.find().populate('users').run(function (err, groups) {
groups[0].users[0].fullname
})
```

The above code works. However the following does not

``` js
GroupModel.find().populate('users', ['fullname']).run(function (err, groups) {
groups[0].users[0].fullname // fullname is undefined
})
```

In the meantime we're not too worried about explicitly setting specific properties and the former is scaling fine for us, but in the future it would be nice for this to work