Wednesday, 5 December 2018

saving models in objection.js

Hey all. I am testing with, and enjoying Objection.jsI am from the ActiveRecord world in Ruby and I was wondering the best way to save objects in ob?for example..gpsSensors = await GpsSensor.query();gpsSensors.forEach(async function(gpsSensor){gpsSensor.position = getPosition();// do other things that modify attributes of the gpsSensorhow would be the best way to go about saving all the modified attributes of the gpsSensor ?i mean, in ActiveRecord i would do gpsSensor.save . and that would write the attributes to the databasei could query().patch() but then i have to go back through all my code and remember what may have changed in the models attributes and I don't want to write every attribute change to the database row as they happen.I have noticed that if i dogpsSensor.position = 72.4and then look at gpsSensor.position it will give me 72.4 regardless of what is in the database. can I patch an entire model?​thanks for any tips​

Submitted December 05, 2018 at 09:21PM by s-keL

No comments:

Post a Comment