balderdashy/sails — pull request #1469 by timestep (2014-03-03 20:18:16+00:00)
Title: #1445 bug issue

https://github.com/balderdashy/sails/pull/1445

This change is only valid if the previous model that was found via Cell.findOne, did not include a populate query.

function deleteOldCell(callBack){
Cell.findOne(cell.id).exec(function (err,c){
if(err){
callBack(err)
}
if(!c || c.length === 0){
callBack(null)
} else {
Cell.destroy({id:c.id}).exec(function (err){
if(err){
callBack(err)
} else {
Cell.publishDestroy(c.id,false,{previous:c})
callBack(null)
}
})
}
})
}
In the event that a populate query was made, such as this:

function deleteOldCell(callBack){
Cell.findOne(cell.id).populate('grid').exec(function (err,c){
if(err){
callBack(err)
}
if(!c || c.length === 0){
callBack(null)
} else {
Cell.destroy({id:c.id}).exec(function (err){
if(err){
callBack(err)
} else {
Cell.publishDestroy(c.id,false,{previous:c})
callBack(null)
}
})
}
})
}
the old version:

ReferencedModel.publishUpdate(previous[association.alias][ReferencedModel.primaryKey]
is a valid reference, since the previous value's association.alias will be a object instead of a number.

There has to be some kind of checking to see whether the previous value being passed in is an object or not and pass in the correct key.