Skip to content

Commit

Permalink
fix(schema): make aliases handle mongoose-lean-virtuals
Browse files Browse the repository at this point in the history
  • Loading branch information
vkarpov15 committed Jan 8, 2020
1 parent 6a8b381 commit 803090d
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions lib/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,16 +143,20 @@ function aliasFields(schema) {

if (alias) {
if ('string' === typeof alias && alias.length > 0) {
if (schema.aliases[alias])
if (schema.aliases[alias]) {
throw new Error('Duplicate alias, alias ' + alias + ' is used more than once');
else
} else {
schema.aliases[alias] = prop;
}

schema
.virtual(alias)
.get((function(p) {
return function() {
return this.get(p);
if (typeof this.get === 'function') {
return this.get(p);
}
return this[p];
};
})(prop))
.set((function(p) {
Expand Down

0 comments on commit 803090d

Please sign in to comment.