1- import type { Collection , CollectionDefaults , HookMetaQueryTracking , StoreSchema , WrappedItemBase } from '@rstore/shared'
1+ import type { Collection , CollectionDefaults , FindOptionsInclude , HookMetaQueryTracking , StoreSchema , WrappedItemBase } from '@rstore/shared'
22import type { MaybeRefOrGetter } from 'vue'
33import type { VueStore } from './store'
44import { tryOnScopeDispose } from '@vueuse/core'
@@ -34,7 +34,7 @@ export function useQueryTracking<TResult>(options: UseQueryTrackingOptions<TResu
3434 return res
3535 } )
3636
37- function handleQueryTracking ( newQueryTracking : HookMetaQueryTracking , result ?: TResult ) {
37+ function handleQueryTracking ( newQueryTracking : HookMetaQueryTracking , result ?: TResult , include : FindOptionsInclude < Collection , CollectionDefaults , StoreSchema > = { } ) {
3838 if ( newQueryTracking . skipped ) {
3939 return
4040 }
@@ -52,7 +52,7 @@ export function useQueryTracking<TResult>(options: UseQueryTrackingOptions<TResu
5252 const list = ( Array . isArray ( _result ) ? _result : [ _result ] )
5353 for ( const item of list ) {
5454 if ( item ) {
55- addToQueryTracking ( newQueryTracking , item )
55+ addToQueryTracking ( newQueryTracking , item , include )
5656 }
5757 }
5858 }
@@ -62,7 +62,7 @@ export function useQueryTracking<TResult>(options: UseQueryTrackingOptions<TResu
6262 const list = Array . isArray ( filteredCached . value ) ? filteredCached . value : ( filteredCached . value ? [ filteredCached . value ] : [ ] )
6363 for ( const item of list ) {
6464 if ( item ) {
65- addToQueryTracking ( queryTracking , item )
65+ addToQueryTracking ( queryTracking , item , include )
6666 }
6767 }
6868 }
@@ -149,7 +149,7 @@ export function useQueryTracking<TResult>(options: UseQueryTrackingOptions<TResu
149149 return obj
150150 }
151151
152- function addToQueryTracking ( qt : HookMetaQueryTracking , item : WrappedItemBase < Collection , CollectionDefaults , StoreSchema > ) {
152+ function addToQueryTracking ( qt : HookMetaQueryTracking , item : WrappedItemBase < Collection , CollectionDefaults , StoreSchema > , include : FindOptionsInclude < Collection , CollectionDefaults , StoreSchema > ) {
153153 if ( ! item . $collection ) {
154154 return
155155 }
@@ -163,13 +163,18 @@ export function useQueryTracking<TResult>(options: UseQueryTrackingOptions<TResu
163163 }
164164 set . add ( item . $getKey ( ) )
165165 for ( const relationName in collection . relations ) {
166- const value = item [ relationName as keyof typeof item ]
167- if ( Array . isArray ( value ) ) {
168- for ( const relatedItem of value ) {
169- if ( relatedItem ) {
170- addToQueryTracking ( qt , relatedItem as WrappedItemBase < Collection , CollectionDefaults , StoreSchema > )
166+ if ( include ?. [ relationName ] && include [ relationName ] !== false ) {
167+ const value = item [ relationName as keyof typeof item ] as unknown as WrappedItemBase < Collection , CollectionDefaults , StoreSchema > | Array < WrappedItemBase < Collection , CollectionDefaults , StoreSchema > >
168+ if ( Array . isArray ( value ) ) {
169+ for ( const relatedItem of value ) {
170+ if ( relatedItem ) {
171+ addToQueryTracking ( qt , relatedItem , include [ relationName ] )
172+ }
171173 }
172174 }
175+ else if ( value != null ) {
176+ addToQueryTracking ( qt , value , include [ relationName ] )
177+ }
173178 }
174179 }
175180 }
0 commit comments