fix(destroy): Properties updated in a beforeDestroy hook are now pers… - #9319
Conversation
|
I think this should be applied on Just tell me, I'm happy to open another PR if needs be. |
| }); | ||
| }); | ||
|
|
||
| it('sets other changed values when soft deleting and a beforeDestroy hooks kicks in', function() { |
There was a problem hiding this comment.
Move to https://github.com/sequelize/sequelize/blob/master/test/integration/hooks/destroy.test.js
Please create a new group for paranoid, under that place this test
| const attribute = this.constructor.rawAttributes[this.constructor._timestampAttributes.deletedAt]; | ||
| const field = attribute.field || this.constructor._timestampAttributes.deletedAt; | ||
| const values = {}; | ||
| const values = Utils.mapValueFieldNames(this, this.changed() || [], this.constructor); |
There was a problem hiding this comment.
it should be mapValueFieldNames(this.dataValues,....
| }); | ||
|
|
||
| it('sets other changed values when soft deleting and a beforeDestroy hooks kicks in', function() { | ||
| const ParanoidUser = this.sequelize.define('ParanoidUser', { |
There was a problem hiding this comment.
Also add a test where you try to update a virtual field in hook and see it doesn't get updated (i.e. it should not throw error for unknown column)
591e2ca to
d1be757
Compare
sushantdhiman
left a comment
There was a problem hiding this comment.
LGTM, some cosmetic changes
| }); | ||
|
|
||
| describe('with paranoid mode enabled', () => { | ||
|
|
| expect(user.virtualField).to.equal(0); | ||
| }); | ||
| }); | ||
|
|
| }); | ||
|
|
||
| }); | ||
|
|
…isted on soft delete. Closes sequelize#9318
d1be757 to
bb42b17
Compare
|
@sushantdhiman Done, sorry for the extra blank lines |
|
Thanks for the appoval, what about the backport to v4 ? |
I'll cherry pick commit from master and port to v4 :) |
|
I was checking other use of this hook, we need to apply this change to Lines 2546 to 2568 in 4caa17c So Also This change may be unexpected for some users and definitely change hook behaviour (#9318 (comment)) so its better to keep this in v5 |
|
Fine to keep this v5 only. Cheers |
|
@sushantdhiman Sorry, I'm puzzled 😀
I'm thinking that the code should individually call That would sum up to something like (pseudo-code): Calling WDYT? |
|
@ddolcimascolo Good question and your pseudo-code is exactly what we should do (like the update case), I reckon we need this change for |
|
Hey guys (and @sushantdhiman), Can you share the status of this contribution? Do you need more code from me or can we consider it good to merge, eventually opening another issue to track the refactoring of the bulk 'destroy' operation? For what it's worth, we're using this patch in production for several weeks now without any issue. It fits well with bonaval/sequelize-temporal#7 which I contributed too. Thanks, David |
…isted on soft delete. Closes #9318
Pull Request check-list
Please make sure to review and check all of these items:
npm run testornpm run test-DIALECTpass with this change (including linting)?Description of change
When getting the list of things to update in the database to perform a soft delete, the code is now considering changed values (through
Model.changed()) instead of only updatingdeletedAt.Closes issue #9318