Still working my way through learning to use an ORM and looking at the docs here: https://coldbox-orm.ortusbooks.com/base-orm-service I can’t seem to find a method that will allow me to update an existing record. There seems to be methods for everything else though.
So I have an existing User record and I want to update the value for one record. I tried using the “executeQuery” method, but that seems to only work for SELECT statements from what I can tell. Any other suggestions helpful.
I basically want to do something like (psuedo-SQL) but via CB ORM
UPDATE Users
SET survey_taken = 0
WHERE user_id = 1234
I came up with a method that works, but not sure if there are other more efficient ways. I essentially had to lookup the record using ormService.get() and then used ormService.populate() to populate the existing object via the memento attribute. I then did an ormService.save(entity=objUser) and that seems to work. I wonder if this could be simplified.
That is the way ORM works, you must get the Entity, populate it and save it.
For a new record is the same process but you would use ormService.new() or provide an empty string to ormService.get("").
if you put the instructions inside a transaction while updating, you can omit the save function, as ORM saves all the dirty entities at the end of the transaction.