-
-
Save troygoode/1731470 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
var mongoose = require('mongoose'); | |
var CompanySchema = new CoreRecord({ | |
name: String, | |
ips: [String] | |
}); | |
CompanySchema.method 'reports', function(cb){ | |
mongoose.model('Report').find({companyId: this._id}, cb); | |
}; | |
exports.Company = CoreScrappy.model('Company',CompanySchema); |
This file contains hidden or 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
#using ICED COFFEE: http://maxtaco.github.com/coffee-script/ | |
mongoose = require 'mongoose' | |
# get company 123's reports | |
await mongoose.model('Company').findById 123, defer err, company | |
await company.reports, defer err, reports | |
console.log company | |
console.log reports |
This file contains hidden or 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
mongoose = require 'mongoose' | |
# get company 123's reports | |
mongoose.model('Company').findById 123, (err, company)-> | |
company.reports (err, reports)-> | |
console.log company #closures yay! | |
console.log reports |
This file contains hidden or 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
var mongoose = require('mongoose'); | |
//get company 123's reports | |
mongoose.model('Company').findById(123, function(err, company){ | |
company.reports(function(err, reports){ | |
console.log(company); //closures yay! | |
console.log(reports); | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment