mongoose model inheritance within javascript prototypal object
Suppose you have a route initialization like this required in your main:
module.exports = function(app) {
for (var name in names) {
var schema = new Schema({}) // schema that accepts anything
, m = mongoose.model(name, schema)
, controller = TextController(m)
app.get('/path', controller.list.bind(controller))
// etc, etc
And TextController is defined externally as:
var TextController = function(Model) {
this.Model = Model
}
TextController.prototype.create = function(req, res) {
var aDoc = this.Model({ // this is the problematic bit
title: req.body.title
, content: req.body.content})
aDoc.save(function(err) {...})
}
For some reason, mongo saves this as an empty document even though the
title and content params are the expected strings. As expected, this.Model
is some sort of mongoose object, but it seems to be rejecting the save or
the instantiation. Any ideas or suggestions?
Note: I added the controller.method.bind(controller) because it was the
only way (I knew of) to get access to this.Model.
No comments:
Post a Comment