Skip to content

Commit 803090d

Browse files
committed
fix(schema): make aliases handle mongoose-lean-virtuals
Backport fix for #6069 and mongoosejs/mongoose-lean-virtuals#6
1 parent 6a8b381 commit 803090d

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

lib/schema.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,16 +143,20 @@ function aliasFields(schema) {
143143

144144
if (alias) {
145145
if ('string' === typeof alias && alias.length > 0) {
146-
if (schema.aliases[alias])
146+
if (schema.aliases[alias]) {
147147
throw new Error('Duplicate alias, alias ' + alias + ' is used more than once');
148-
else
148+
} else {
149149
schema.aliases[alias] = prop;
150+
}
150151

151152
schema
152153
.virtual(alias)
153154
.get((function(p) {
154155
return function() {
155-
return this.get(p);
156+
if (typeof this.get === 'function') {
157+
return this.get(p);
158+
}
159+
return this[p];
156160
};
157161
})(prop))
158162
.set((function(p) {

0 commit comments

Comments
 (0)