@@ -251,10 +251,8 @@ export function subscribeToFindMany<const S extends AnyNoContext>(
251251 if ( ! decodedEntitiesCache . has ( typeName ) ) {
252252 const entities = findMany ( handle , type ) ;
253253 const entitiesMap = new Map ( ) ;
254- const relationParent = new Map ( ) ;
255254 for ( const entity of entities ) {
256255 entitiesMap . set ( entity . id , entity ) ;
257- relationParent . set ( entity . id , new Map ( ) ) ;
258256 }
259257
260258 const queries = new Map < string , QueryEntry > ( ) ;
@@ -265,13 +263,31 @@ export function subscribeToFindMany<const S extends AnyNoContext>(
265263 isInvalidated : false ,
266264 } ) ;
267265
268- decodedEntitiesCache . set ( typeName , {
266+ const cacheEntry : DecodedEntitiesCacheEntry = {
269267 decoder : decode ,
270268 type,
271269 entities : entitiesMap ,
272270 queries,
273271 isInvalidated : false ,
274- } ) ;
272+ } ;
273+
274+ decodedEntitiesCache . set ( typeName , cacheEntry ) ;
275+
276+ for ( const entity of entities ) {
277+ for ( const [ , value ] of Object . entries ( entity ) ) {
278+ if ( Array . isArray ( value ) ) {
279+ for ( const relationEntity of value ) {
280+ let relationParentEntry = entityRelationParentsMap . get ( relationEntity . id ) ;
281+ if ( ! relationParentEntry ) {
282+ relationParentEntry = [ ] ;
283+ entityRelationParentsMap . set ( relationEntity . id , relationParentEntry ) ;
284+ }
285+
286+ relationParentEntry . push ( cacheEntry ) ;
287+ }
288+ }
289+ }
290+ }
275291 }
276292
277293 const allTypes = new Set < S > ( ) ;
0 commit comments