Skip to content

Instantly share code, notes, and snippets.

@nooga
Created July 10, 2012 17:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nooga/3084757 to your computer and use it in GitHub Desktop.
Save nooga/3084757 to your computer and use it in GitHub Desktop.
/* category.js */
var mongoose = require('mongoose')
, Schema = mongoose.Schema
, ObjectId = Schema.ObjectId;
var Category = new Schema({
...
});
Category.statics.foobar = function() {
...
}
module.exports = mongoose.model('Category', Category);
/* photo.js */
var mongoose = require('mongoose')
, Schema = mongoose.Schema
, ObjectId = Schema.ObjectId
, Category = require('./category'); //defined here
var Photo = new Schema({
...
});
Photo.statics.getRandomFromCat = function(category_id, cb) {
console.log("getRandomFromCat",category_id);
if(category_id) {
Category.findById(category_id, function(err, cat) {
if(err) throw err;
//....
}
} else {
//....
}
});
module.exports = mongoose.model('User', User);
@nooga
Copy link
Author

nooga commented Jul 10, 2012

TypeError: Object function model() {
Model.apply(this, arguments);
} has no method 'getById'

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