Permalink
Browse files

Merge branch 'master' into on-the-fly-schemas

  • Loading branch information...
2 parents 60a6891 + d850866 commit 8f473b06f5acc0d3ef6224b774cb61bfa4d9571b @bnoguchi bnoguchi committed May 12, 2011
Showing with 13 additions and 4 deletions.
  1. +1 −1 README.md
  2. +7 −3 lib/mongoose/schema.js
  3. +5 −0 test/schema.test.js
View
@@ -3,7 +3,7 @@ Mongoose 1.0
## What's Mongoose?
-Mongoose is a MongoDB object modeling tool designed to work in an asychronous
+Mongoose is a MongoDB object modeling tool designed to work in an asynchronous
environment.
Defining a model is as easy as:
View
@@ -40,9 +40,13 @@ function Schema (obj, options) {
if (!this.paths['_id'])
this.add({ _id: {type: ObjectId, auto: true} });
- if (!this.paths['id']) this.virtual('id').get(function () {
- return this._id.toString();
- });
+ if (!this.paths['id'] && !this.options.noVirtualId) {
+ this.virtual('id').get(function () {
+ return this._id.toString();
+ });
+ }
+
+ delete this.options.noVirtualId;
};
/**
View
@@ -768,6 +768,11 @@ module.exports = {
'test GH-298 - The default creation of a virtual `id` should be muted when someone defines their own `id` attribute': function () {
new Schema({ id: String });
+ },
+
+ 'allow disabling the auto .id virtual': function () {
+ var schema = new Schema({ name: String }, { noVirtualId: true });
+ should.strictEqual(undefined, schema.virtuals.id);
}
};

0 comments on commit 8f473b0

Please sign in to comment.