OtherInstance.save is not a function [hasOne Association]
DimitarDechew opened this issue · 0 comments
DimitarDechew commented
Yo guys,
I'm trying to change the group of item using hasOne association, but apparently I cannot do that. I'm getting this error:
/home/ghostbg/Projects/qsell-project/node_modules/orm/lib/Associations/One.js:253
OtherInstance.save({}, { saveAssociations: false }, function (err) {
^
TypeError: OtherInstance.save is not a function
at Object.value (/home/ghostbg/Projects/qsell-project/node_modules/orm/lib/Associations/One.js:253:23)
at /home/ghostbg/Projects/qsell-project/controllers/device.js:19:14
at /home/ghostbg/Projects/qsell-project/node_modules/orm/lib/ChainFind.js:212:16
at /home/ghostbg/Projects/qsell-project/node_modules/orm/lib/ChainFind.js:88:16
at /home/ghostbg/Projects/qsell-project/node_modules/async/dist/async.js:1140:9
at /home/ghostbg/Projects/qsell-project/node_modules/async/dist/async.js:473:16
at iteratorCallback (/home/ghostbg/Projects/qsell-project/node_modules/async/dist/async.js:1064:13)
at /home/ghostbg/Projects/qsell-project/node_modules/async/dist/async.js:969:16
at /home/ghostbg/Projects/qsell-project/node_modules/async/dist/async.js:1137:13
at Object.<anonymous> (/home/ghostbg/Projects/qsell-project/node_modules/orm/lib/Model.js:127:16)
at /home/ghostbg/Projects/qsell-project/node_modules/orm/lib/Instance.js:32:10
at Array.map (<anonymous>)
at emitEvent (/home/ghostbg/Projects/qsell-project/node_modules/orm/lib/Instance.js:31:19)
at /home/ghostbg/Projects/qsell-project/node_modules/orm/lib/Instance.js:768:7
at process._tickCallback (internal/process/next_tick.js:61:11)
Here's my code:
update: async function(m, db, socket) {
var targetCluster = db.models.cluster.findAsync({ id : m.targetCluster });
db.models.device.find({ id : m.deviceID }).first(function(err, device) {
if(err) throw err;
device.setCluster(targetCluster, function(err) {
if(err) throw err;
})
})
}