Skip to content

Commit

Permalink
Coerce ids in other publish* methods (pubsub hook)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikermcneil committed Dec 24, 2014
1 parent 5644a31 commit 0c2cce6
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions lib/hooks/pubsub/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -741,6 +741,15 @@ module.exports = function(sails) {
this.beforePublishDestroy(id, 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,
Expand Down Expand Up @@ -975,6 +984,16 @@ module.exports = function(sails) {
this.beforePublishRemove(id, alias, idRemoved, req);
}

// 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
}

// If a request object was sent, get its socket, otherwise assume a socket was sent.
var socketToOmit = (req && req.socket ? req.socket : req);

Expand Down Expand Up @@ -1054,6 +1073,16 @@ module.exports = function(sails) {

var id = values[this.primaryKey];

// 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
}

// If any of the added values were association attributes, publish add or remove messages.
_.each(values, function(val, key) {

Expand Down

0 comments on commit 0c2cce6

Please sign in to comment.