dzdmmtf
dzdmmtf

Reputation: 499

Sequelize upsert returns undefined _previousDataValues

I used Model.upsert function in sequelize. This method returns [record, created] that the record field is the upserted instance. I called this function with the exact duplicate data from database and in the return result, all the fields in _previousDataValues are undefined and the _changed Set contains all the fields.

I need a way to understand which fields have been changed (in this case zero fields because data is duplicate) without using a find query. One way is to compare _previousDataValues with dataValues but all the fields _previousDataValues are undefined. Another way would be through _changed but the _changed contains all fields although no field has been changed.

I'd appreciate if someone helps me to get the changed fields.

Upvotes: 0

Views: 679

Answers (1)

Anatoly
Anatoly

Reputation: 22803

_previousDataValues stores values that were before you call set method of a mode instance to change some values, see set.
_previousDataValues is not intended to get previous values from DB after an UPDATE query was executed.

Upvotes: 2

Related Questions