@@ -29,7 +29,7 @@ internal class HookExecutorHelper : IHookExecutorHelper
2929 public HookExecutorHelper (
3030 IGenericProcessorFactory genericProcessorFactory ,
3131 IResourceGraph graph ,
32- IJsonApiContext context = null
32+ IJsonApiContext context
3333 )
3434 {
3535 _genericProcessorFactory = genericProcessorFactory ;
@@ -81,39 +81,38 @@ public IResourceHookContainer<TEntity> GetResourceHookContainer<TEntity>(Resourc
8181 return ( IResourceHookContainer < TEntity > ) GetResourceHookContainer ( typeof ( TEntity ) , hook ) ;
8282 }
8383
84- public IEnumerable LoadDbValues ( PrincipalType repositoryEntityType , Type affectedHookEntityType , IEnumerable entities , ResourceHook hook , params RelationshipProxy [ ] relationships )
84+ public IEnumerable LoadDbValues ( PrincipalType entityTypeForRepository , IEnumerable entities , ResourceHook hook , params RelationshipProxy [ ] relationships )
8585 {
86- if ( ! ShouldLoadDbValues ( affectedHookEntityType , hook ) ) return null ;
87-
8886 var paths = relationships . Select ( p => p . Attribute . RelationshipPath ) . ToArray ( ) ;
89- var idType = GetIdentifierType ( repositoryEntityType ) ;
87+ var idType = GetIdentifierType ( entityTypeForRepository ) ;
9088 var parameterizedGetWhere = GetType ( )
9189 . GetMethod ( nameof ( GetWhereAndInclude ) , BindingFlags . NonPublic | BindingFlags . Instance )
92- . MakeGenericMethod ( repositoryEntityType , idType ) ;
90+ . MakeGenericMethod ( entityTypeForRepository , idType ) ;
9391 var casted = ( ( IEnumerable < object > ) entities ) . Cast < IIdentifiable > ( ) ;
9492 var ids = casted . Select ( e => e . StringId ) . Cast ( idType ) ;
9593 var values = ( IEnumerable ) parameterizedGetWhere . Invoke ( this , new object [ ] { ids , paths } ) ;
96- return values ;
94+ if ( values == null ) return null ;
95+ return ( IEnumerable ) Activator . CreateInstance ( typeof ( HashSet < > ) . MakeGenericType ( entityTypeForRepository ) , values . Cast ( entityTypeForRepository ) ) ;
9796 }
9897
9998 public HashSet < TEntity > LoadDbValues < TEntity > ( IEnumerable < TEntity > entities , ResourceHook hook , params RelationshipProxy [ ] relationships ) where TEntity : class , IIdentifiable
10099 {
101100 var entityType = typeof ( TEntity ) ;
102- var dbValues = LoadDbValues ( entityType , entityType , entities , hook , relationships ) ? . Cast < TEntity > ( ) ;
101+ var dbValues = LoadDbValues ( entityType , entities , hook , relationships ) ? . Cast < TEntity > ( ) ;
103102 if ( dbValues == null ) return null ;
104103 return new HashSet < TEntity > ( dbValues ) ;
105104 }
106105
107106
108- bool ShouldLoadDbValues ( DependentType entityType , ResourceHook hook )
107+ public bool ShouldLoadDbValues ( Type entityType , ResourceHook hook )
109108 {
110109 var discovery = GetHookDiscovery ( entityType ) ;
111110
112- if ( discovery . DatabaseDiffDisabledHooks . Contains ( hook ) )
111+ if ( discovery . DatabaseValuesDisabledHooks . Contains ( hook ) )
113112 {
114113 return false ;
115114 }
116- else if ( discovery . DatabaseDiffEnabledHooks . Contains ( hook ) )
115+ else if ( discovery . DatabaseValuesEnabledHooks . Contains ( hook ) )
117116 {
118117 return true ;
119118 }
@@ -177,7 +176,9 @@ public Dictionary<RelationshipProxy, IEnumerable> LoadImplicitlyAffected(
177176 foreach ( var kvp in principalEntitiesByRelation )
178177 {
179178 if ( IsHasManyThrough ( kvp , out var principals , out var relationship ) ) continue ;
180- var includedPrincipals = LoadDbValues ( relationship . PrincipalType , relationship . DependentType , principals , ResourceHook . BeforeImplicitUpdateRelationship , relationship ) ;
179+
180+ // note that we dont't have to check if BeforeImplicitUpdate hook is implemented. If not, it wont ever get here.
181+ var includedPrincipals = LoadDbValues ( relationship . PrincipalType , principals , ResourceHook . BeforeImplicitUpdateRelationship , relationship ) ;
181182
182183 foreach ( IIdentifiable ip in includedPrincipals )
183184 {
0 commit comments