nielsgl/sequelize-paper-trail

Field 'model' doesn't have a default value in version 2.1.0

ksfreitas opened this issue · 3 comments

After update to version 2.1.0, cannot register any revision:

     sqlMessage: 'Field \'model\' doesn\'t have a default value',
     sql: 'INSERT INTO `revisions` (`id`,`createdAt`,`updatedAt`,`revision`) VALUES (DEFAULT,\'2019-01-03 03:58:29\',\'2019-01-03 03:58:29\',1);' },

Observe that some fields are not in SQL, like model, documentId, document and userId.

I located the problem in line 321 in opt param passed in save call.

If the opt is removed like in the old version, the function back work (I don't know why yet).

Origin commit e015126

If only transaction is passed in a new opt object, works... The cause is unknown, but this keep paper-trail transactional and fix my problem...

Any ideas?

I found the error, the code is really wrong: the opt received were from the entity context (where all is origined), causing a mess inside the sequelize, at least in version 4.42.0. Look in the image bellow, the fields are being reload with entity fields (overiding the Revision fields)...

anotacao 2019-01-03 024150

Ah 🤦‍♂️ I tested it with a quite old version of sequelize in which it did work, thanks a lot for investigating and resolving it @ksfreitas 🍺