I am really digging this ORM. As I understand it, columns of an sql database are returned as object properties in javascript. I have been able to query and then modify an object after it is retrieved. like so
sensors = await Sensor.query()
.where("monitorId", 245)
if (sensor.length > 0){
mySensor = sensors[0];
mySensor.monitorID = 7874;
}
Now I have a sensor with a monitorID of 7874
is there a simple method to save this object back without using patch() ?
I ask because I write code for a data processing lab where this property may change a few times, and I dont want to have to track several objects and changes over the course of the process nor save the record every time a property is changed.
is this possible?
Yes,
you can say:
await mySensor.$query().patch()
You don't need to keep track of stuff even with the static patch method because you can always do this:
await Sensor.query().patch(mySensor).where('id', mySensor.id)
findById shortcut by the way.
This rocks, thanks !
Most helpful comment
Yes,
you can say:
You don't need to keep track of stuff even with the static
patchmethod because you can always do this:findByIdshortcut by the way.