Skip to content

Commit

Permalink
Coerce pk value in publishUpdate (pubsub hook)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikermcneil committed Dec 24, 2014
1 parent 966e402 commit 5644a31
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/hooks/pubsub/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,16 @@ module.exports = function(sails) {
this.beforePublishUpdate(id, changes, req, options);
}

// Coerce id to match the attribute type of the primary key of the model
try {
var pkAttrDef = this.attributes[this.primaryKey];
if (pkAttrDef.type === 'integer') { id = +id; }
else if (pkAttrDef.type === 'string') { id = id+''; }
}
catch(e){
// well... worth a shot
}

var data = {
model: this.identity,
verb: 'update',
Expand Down

0 comments on commit 5644a31

Please sign in to comment.