Created
January 30, 2012 19:57
-
-
Save shiawuen/1706310 to your computer and use it in GitHub Desktop.
Was trying to query products based on id passed in, but I got all of the records instead of the one with category id given
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 Product = new Schema({ | |
quantity: { type: Number } | |
, title: { type: String, trim: true } | |
, category: { type: ObjectId, ref: 'Category' } | |
}) | |
var Model = db.model('Product', Product); | |
Product | |
.statics | |
.byCategoryId = function(id, next) { | |
var q = Model.find() | |
q.where('category', id) // << Works! | |
// q.where({ category: id }) // << Nope, why? | |
q.exec(next); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment