Created
November 26, 2012 17:34
-
-
Save jwietelmann/4149554 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
models.util = { | |
singleSubDoc: function(schema, virtualName) { | |
var realName = '_' + virtualName; | |
schema.virtual(virtualName) | |
.get(function() { | |
if(this[realName].length) return this[realName][0]; | |
else return null; | |
}) | |
.set(function(value) { | |
this[realName] = [value]; | |
}); | |
; | |
} | |
}; | |
models.SchemaWithSingleLocation = new Schema({ | |
_location: [Location], | |
}); | |
models.util.singleSubDoc(models.SchemaWithSingleLocation, 'location'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment