From 2b035c3dae44a24589bab3a402b299ce7cbf3823 Mon Sep 17 00:00:00 2001 From: DallonF Date: Fri, 29 Jun 2012 09:27:40 -0700 Subject: [PATCH] Throw error on PUT without id. --- lib/resources/collection.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/resources/collection.js b/lib/resources/collection.js index 76d3940..013d620 100644 --- a/lib/resources/collection.js +++ b/lib/resources/collection.js @@ -130,7 +130,7 @@ Collection.prototype.sanitize = function (body) { Collection.prototype.handle = function (ctx) { // set id one wasnt provided in the query - ctx.query.id = ctx.query.id || this.parseId(ctx); + ctx.query.id = ctx.query.id || this.parseId(ctx) || (ctx.body && ctx.body.id); if (ctx.req.internal) { ctx.session.internal = true; @@ -140,8 +140,12 @@ Collection.prototype.handle = function (ctx) { case 'GET': this.find(ctx.session, ctx.query, ctx.dpd, ctx.done); break; - case 'POST': case 'PUT': + if (!ctx.query.id) { + ctx.done("must provide id to update an object"); + break; + } + case 'POST': this.save(ctx.session, ctx.body, ctx.query, ctx.dpd, ctx.done); break; case 'DELETE':