Skip to content

Instantly share code, notes, and snippets.

@mappum
Created May 23, 2012 06:31
Show Gist options
  • Save mappum/2773551 to your computer and use it in GitHub Desktop.
Save mappum/2773551 to your computer and use it in GitHub Desktop.
var Schema = require('mongoose').Schema,
ObjectId = Schema.ObjectId,
Transaction = require('./transaction.js');
var Comment = module.exports = new Schema({
'author': String,
'body': String,
'date': Date,
'parent': ObjectId,
'score': {'type': Number, 'default': 0},
'transactions': [Transaction]
});
node.js:201
throw e; // process.nextTick error, or 'error' event on first tick
^
TypeError: Cannot read property 'states' of undefined
at EmbeddedDocument.isDirectModified (/home/mappum/aptt/node_modules/mongoose/lib/document.js:673:36)
at EmbeddedDocument.set (/home/mappum/aptt/node_modules/mongoose/lib/document.js:417:17)
at EmbeddedDocument.parent (/home/mappum/aptt/node_modules/mongoose/lib/document.js:993:45)
at EmbeddedDocument.EmbeddedDocument (/home/mappum/aptt/node_modules/mongoose/lib/types/embedded.js:19:15)
at new EmbeddedDocument (/home/mappum/aptt/node_modules/mongoose/lib/schema/documentarray.js:26:17)
at DocumentArray.SchemaArray (/home/mappum/aptt/node_modules/mongoose/lib/schema/array.js:48:19)
at new DocumentArray (/home/mappum/aptt/node_modules/mongoose/lib/schema/documentarray.js:42:13)
at Function.interpretAsType (/home/mappum/aptt/node_modules/mongoose/lib/schema.js:220:14)
at Schema.path (/home/mappum/aptt/node_modules/mongoose/lib/schema.js:185:29)
at Schema.add (/home/mappum/aptt/node_modules/mongoose/lib/schema.js:121:12)
var mongoose = require('mongoose'),
schema = require('./schemas/item.js');
module.exports = mongoose.model('Item', schema);
var Schema = require('mongoose').Schema,
Comment = require('./comment.js'),
Transaction = require('./transaction.js');
var Item = module.exports = new Schema({
'title': String,
'author': String,
'body': String,
'link': String,
'class': {'type': String, 'lowercase': true}, // the type of post (e.g 'youtube', 'text')
'tags': {'type': [String], 'index': true},
'date': {'type': Date, 'default': Date.now},
'comments': [Comment],
'score': {'type': Number, 'default': 0},
'transactions': [Transaction]
});
@ljharb
Copy link

ljharb commented May 23, 2012

var Schema = require('mongoose').Schema,
    ObjectId = Schema.ObjectId,
    Transaction = require('./transaction.js');

var Comment = module.exports = new Schema({ 
    author: {type: String},
    body: {type: String},
    date: {type: Date},

    parent: {type: ObjectId},

    score: {type: Number, 'default': 0},
    transactions: [{type: ObjectId, ref: 'Transaction'}]
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment