how can i check if value is changed on Server side code ?

i’m familiar with the basic event handlers , but my need in this case is bit different say i have a table Called “Cars” and another table “Drivers” and “Cars” table have a row named “Voters” which is related to “Drivers” table in (one to many) relation. now how can i trigger an action when “Voter’s” (a row from Cars table) value increases or decreases ? i have different action to do on different situations (execute actionA when Voters reduces or execute actionB when Voters increases )

let me know if my question is not clear enough

Something like this should work

class Cars extends Backendless.ServerCode.PersistenceItem {

Backendless.ServerCode.Persistence.beforeUpdate('Cars', function(req) {
   const car = req.item
   return Cars.findById(car.objectId).then(oldCar => {
      if (car.Voters < oldCar.Voters) {
      } else if (car.Voters > oldCar.Voters) {
}, true) //important to be as true

@vitaly thanks for responding , i’m still not able to figure out the values of Variable ,

public void beforeUpdate( RunnerContext context, Cars cars ) throws Exception
// can you explain here what to do with this ‘cars’ parameter ?

// what is oldCar here ??

In Java it would look like:

Cars oldCar = Backendless.Data.of( Cars.class ).findById( cars.getObjectId(), 1 );
if( oldCar.getVoters().size() < cars.getVoters().size() )
// Action A
else if( oldCar.getVoters().size() < cars.getVoters().size() )
// Action B

action A or B are ever getting called cause the value of "oldCar.getVoters().size() " & cars.getVoters().size() always remains same

Talking about beforeUpdate handler, oldCar.getVoters().size() is the number of related objects currently persisted in the database and cars.getVoters().size() is the number of the relations you’ve just changed and sent to ‘update’ method.