Hi,
The default behavior of object update ( PUT ) is just to update the dirty / changed properties, I take it.
That’s working fine unless I put a beforeUpdate event handler into my business logic.
Even an empty, without a single of code, beforeUpdate handler causes total reset to the object (except the objectId) as if it’s created first time.
Is this the expected behavior?
Does implementing a beforeUpdate put all the responsibility regarding the object update to the developer?
If that is the situation, no need to read later.
If not, though, here is a little more detail about this particular project:
There is a simple contacts table in my app which holds usual suspects as e-mail, name, phone, etc.
Contacts also has a special field as Search Tokens to optimize the real-time search in the clients.
Search Tokens consists of, as you might have guessed, filtered / lower-cased / sorted keywords of all other properties.
When the contact’s created the first time, a beforeCreate handler builds this field.
But I also need to update that, whenever the contact is updated.
Here comes the aforementioned problem.
Client app sends a PUT for just the name, but Backendless throws an error as “email cannot be empty”.
Which means, most probably, Backendless expects an E-mail field but it shouldn’t; this is just an update.
When the client app sends the required fields as well, then Backendless resets all non-required fields, simply because they weren’t sent.
Again, if this is the default behavior, I can find a workaround.
I wouldn’t prefer it, but I can fetch the object in beforeUpdate, update dirty fields manually, then let Backendless save it safe and sound.
Thanks for all your help and insights.
Best,
~ Fatih