0

I would like to be able to track the mutated (modified) attributes of an object in sails during afterUpdate lifecycle callback.

Assuming an object is updated I would like to know which attribute has been modified during the update operation, I've been using sails-mongo and I believe I could write a proxy adapter that keep a local instance and attach it to the one thats going to be modified and do a diff on save but there might be an already existing way of doing so :)

Thanks !

Adraen
  • 25
  • 3

1 Answers1

1

Waterline doesn't currently have a built in diff mechanism. To accomplish this you can explore the use of native queries where some databases will allow you to return the values being updated or store the previous records in a diff on the record in the database.

afterUpdate won't be able to handle this because by then the results have already been updated in the database. You could write a controller method that uses the same criteria to capture all the records before you issue the update criteria.

particlebanana
  • 2,416
  • 21
  • 22