@@ -14,24 +14,24 @@ function shouldUpdate(
1414 computedField : string ,
1515 val : Record < string , any > ,
1616 oldVal : Record < string , any > ,
17- pk : string | number ,
1817) {
19- // creating new item
20- if ( val . id && pk === '+' ) {
21- return false ;
22- }
23-
18+ const changedFields = [ ] ;
2419 for ( const key of Object . keys ( { ...oldVal , ...val } ) ) {
2520 if (
2621 key !== computedField &&
27- checkFieldInTemplate ( template , key ) &&
2822 val [ key ] !== oldVal [ key ] &&
2923 JSON . stringify ( val [ key ] ) !== JSON . stringify ( oldVal [ key ] )
3024 ) {
31- return true ;
25+ changedFields . push ( key ) ;
3226 }
3327 }
34- return false ;
28+
29+ if ( ! changedFields . length ) {
30+ // update even if no fields changed
31+ return true ;
32+ }
33+
34+ return changedFields . some ( ( field ) => checkFieldInTemplate ( template , field ) ) ;
3535}
3636
3737export const useCollectionRelations = ( collection : string ) : Ref < Relation [ ] > => {
@@ -49,14 +49,16 @@ interface IRelationUpdate {
4949export const useDeepValues = (
5050 values : Ref < Record < string , any > > ,
5151 relations : Ref < Relation [ ] > ,
52- collection : string ,
53- computedField : string ,
54- pk : string | number ,
52+ collection : Ref < string > ,
53+ computedField : Ref < string > ,
54+ pk : Ref < string | number > ,
5555 template : string
5656) => {
5757 const api = useApi ( ) ;
58- const { currentUser } = useStores ( ) . useUserStore ( ) ;
59- const finalValues = ref < Record < string , any > > ( { } ) ;
58+ const userStore = useStores ( ) . useUserStore ( ) ;
59+ const finalValues = ref < Record < string , any > > ( {
60+ __currentUser : userStore . currentUser ,
61+ } ) ;
6062 let fieldCache : Record < string , any > = { } ;
6163 let itemCache : Record < string , any > = { } ;
6264 // Directus store o2m value as reference so when o2m updated, val & oldVal in watch are the same.
@@ -71,7 +73,7 @@ export const useDeepValues = (
7173 async ( val , oldVal ) => {
7274 const valObj = JSON . parse ( val ) ;
7375 const oldValObj = oldVal !== undefined ? JSON . parse ( oldVal ) : { } ;
74- if ( ! shouldUpdate ( template , computedField , valObj , oldValObj , pk ) ) {
76+ if ( ! shouldUpdate ( template , computedField . value , valObj , oldValObj ) ) {
7577 return ;
7678 }
7779
@@ -91,7 +93,7 @@ export const useDeepValues = (
9193 continue ;
9294 }
9395
94- const isM2O = relation . collection === collection ;
96+ const isM2O = relation . collection === collection . value ;
9597 const fieldName = isM2O ? relation . meta ?. many_field : relation . meta ?. one_field ;
9698
9799 let fieldChanges = valObj [ fieldName ! ] as IRelationUpdate ?? {
@@ -195,7 +197,7 @@ export const useDeepValues = (
195197 relationalData [ key ] = isM2O ? arrayOfData [ 0 ] : arrayOfData ;
196198 }
197199
198- finalValues . value = { ...valObj , ...relationalData , __currentUser : currentUser } ;
200+ finalValues . value = { ...valObj , ...relationalData , __currentUser : userStore . currentUser } ;
199201 } ,
200202 {
201203 deep : false ,
0 commit comments