node-restful
node-restful copied to clipboard
PUT an element to an array
Given this model:
var Task = app.task = restful.model('task', mongoose.Schema({
title: { type: 'string', require: true },
body: { type: 'string', require: true },
user_id: { type: 'ObjectId', ref: 'user', require: true },
comments: [{
body: { type: 'string', require: true },
votes: {
user_id: { type: 'ObjectId', ref: 'user' },
score: { type: 'number' }
},
author: { type: 'ObjectId', ref: 'user' },
}],
}))
.methods(['get', 'delete', 'put', 'post' ]);
Is this possible to PUT
a Comment
to an existing Task
?
I was looking to use an URL like /tasks/:id:/comments
and PUT
a comment object to it.
Currently this isn't actually supported, but I want to :)
The correct verb in this case would be POST
though
Thanks.
Are you aware of any workaround? Perhaps defining a custom route?
You should be able to do
Task.route('comments', 'post', function(req, res, next) {
// Do whatever you want here
})
This is the PATCH
REST method.
PUT
replaces the whole document whereas PATCH
just updates the field you provide. If you still need this wait for #152 to be merged otherwise could you please close this.