Permalink
Browse files

allow default functions for Array types

  • Loading branch information...
1 parent a0a4b03 commit 96bf86c469e921e5f4f74760d7be9c18807220c1 @aheckmann aheckmann committed Mar 21, 2011
Showing with 9 additions and 3 deletions.
  1. +9 −3 lib/mongoose/schema/array.js
@@ -31,11 +31,17 @@ function SchemaArray (key, cast, options) {
}
var self = this
- , defaultArr;
+ , defaultArr
+ , fn;
+
+ if (this.defaultValue) {
+ defaultArr = this.defaultValue;
+ fn = 'function' == typeof defaultArr;
+ }
- if (this.defaultValue) defaultArr = this.defaultValue;
this.default(function(){
- return new MongooseArray(defaultArr || [], self.path, this);
+ var arr = fn ? defaultArr() : defaultArr || [];
+ return new MongooseArray(arr, self.path, this);
});
};

0 comments on commit 96bf86c

Please sign in to comment.