-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
virtual path on array #2326
Comments
That's weird, that should work in theory. I'll investigate. |
maybe my fault. here is some test code: describe('gh-2306', function () {
it('allow define virtual on non-object path', function () {
var db = start();
var schema = new mongoose.Schema({ num: Number, str: String, nums: [Number] });
schema.virtual('num.power').get(function () {
return this.num * this.num;
});
schema.virtual('str.upper').get(function () {
return this.str.toUpperCase();
});
schema.virtual('nums.last').get(function () {
return this.nums[this.nums.length - 1];
});
var M = db.model('gh2306', schema);
var m = new M({ num: 2, str: 'a', nums: [1,2,3] });
assert.equal(m.num.power, 4);
assert.equal(m.str.upper, 'A');
assert.equal(m.nums.last, 3);
});
}); |
There is no good way to support this right now because getters and setters do not go through the You can access the virtuals in the test above as |
+1 |
We can't support |
feat: allow defining virtuals on arrays, not just array elements
in mongose guild doc there is a cool example. define
.full
virtual on sub documentsname: {first:String, last:String}
. then get virtual value byname.full
.but if i define virtual on array like this:
i cannot get it by dot path
nums.odd
. only write like thismodel.get('nums.odd')
.is there a way to fix this?
i'm running mongoose@3.9.3
The text was updated successfully, but these errors were encountered: