@@ -9,9 +9,22 @@ import type { BaseModel } from '@adonisjs/lucid/orm'
9
9
import type { NormalizeConstructor } from '@adonisjs/core/types/helpers'
10
10
import type { AttributeOfModelWithAttachment } from '../types/mixin.js'
11
11
12
- import { beforeSave , afterSave , beforeDelete , afterFind , afterFetch , afterPaginate } from '@adonisjs/lucid/orm'
13
- import { persistAttachment , commit , rollback , generateVariants , preComputeUrl } from '../utils/actions.js'
14
- import { clone , getAttachmentAttributeNames } from '../utils/helpers.js'
12
+ import {
13
+ beforeSave ,
14
+ afterSave ,
15
+ beforeDelete ,
16
+ afterFind ,
17
+ afterFetch ,
18
+ afterPaginate ,
19
+ } from '@adonisjs/lucid/orm'
20
+ import {
21
+ persistAttachment ,
22
+ commit ,
23
+ rollback ,
24
+ generateVariants ,
25
+ preComputeUrl ,
26
+ } from '../utils/actions.js'
27
+ import { clone , getAttachmentAttributeNames , getDirtyAttachmentAttributeNames } from '../utils/helpers.js'
15
28
import { defaultStateAttributeMixin } from '../utils/default_values.js'
16
29
17
30
export const Attachmentable = < Model extends NormalizeConstructor < typeof BaseModel > > (
@@ -39,7 +52,7 @@ export const Attachmentable = <Model extends NormalizeConstructor<typeof BaseMod
39
52
40
53
@beforeSave ( )
41
54
static async beforeSaveHook ( modelInstance : ModelWithAttachment ) {
42
- const attachmentAttributeNames = getAttachmentAttributeNames ( modelInstance )
55
+ const attachmentAttributeNames = getDirtyAttachmentAttributeNames ( modelInstance )
43
56
44
57
/**
45
58
* Empty previous $attachments
@@ -49,11 +62,9 @@ export const Attachmentable = <Model extends NormalizeConstructor<typeof BaseMod
49
62
/**
50
63
* Set attributes Attachment type modified
51
64
*/
52
- attachmentAttributeNames . forEach ( ( attributeName ) => {
53
- if ( modelInstance . $dirty [ attributeName ] ) {
54
- modelInstance . $attachments . attributesModified . push ( attributeName )
55
- }
56
- } )
65
+ attachmentAttributeNames . forEach ( ( attributeName ) =>
66
+ modelInstance . $attachments . attributesModified . push ( attributeName )
67
+ )
57
68
58
69
/**
59
70
* Persist attachments before saving the model to the database. This
0 commit comments