1

I cannot update a datetime type value in a table. (VIGENCIA) I`m using AdonisJS and Lucid models, and MySQL, but no matter what i try it remains the same. Sorry for english second language.

const user = await auth.getUser();
      const pack = await Paquete.find(request.all().selectedPackage);
      let userUpdate = await Usuario.find(user.id);
      console.log(userUpdate);
      userUpdate.VIGENCIA.setDate(userUpdate.VIGENCIA.getDate()+pack.VALIDEZ);
      userUpdate.SALDO_CLASES = userUpdate.SALDO_CLASES+pack.CLASES;
      let payment = new Pago();
      payment.VALIDEZ = userUpdate.VIGENCIA;
      payment.PAQUETES_id= pack.id;
      payment.CLIENTES_id = userUpdate.id; 
        await userUpdate.save();
        await payment.save();

It updates SALDO_CLASE value without an issue. The current piece of code is the last thing i tried.

  • 1
    Hi. In my experience it may well be that there is a change detection on `.VIGENCIA`. After updating the date add the line `userUpdate.VIGENCIA = userUpdate.VIGENCIA;` – gwest7 Jan 17 '20 at 05:19

1 Answers1

0

You must use this synthax : <model>.<field> = <new_value>

Something like :

...
let date = new Date(userUpdate.VIGENCIA); // Get date object

userUpdate.VIGENCIA = <new_date>;
...
await userUpdate.save();
crbast
  • 2,192
  • 1
  • 11
  • 21