@@ -72,7 +72,7 @@ def authorize_show_relationship
7272 related_resource =
7373 case relationship
7474 when JSONAPI ::Relationship ::ToOne
75- parent_resource . public_send ( params [ :relationship_type ] . to_sym )
75+ resources_from_relationship ( source_klass , source_id , relationship . type , context ) . first
7676 when JSONAPI ::Relationship ::ToMany
7777 # Do nothing — already covered by policy scopes
7878 else
@@ -91,10 +91,13 @@ def authorize_show_related_resource
9191
9292 source_resource = source_klass . find_by_key ( source_id , context : context )
9393
94- related_resource = source_resource . public_send ( relationship_type )
94+ related_resource = resources_from_relationship (
95+ source_klass , source_id , relationship_type , context
96+ ) &.first
9597
9698 source_record = source_resource . _model
9799 related_record = related_resource . _model unless related_resource . nil?
100+
98101 authorizer . show_related_resource (
99102 source_record : source_record , related_record : related_record
100103 )
@@ -282,6 +285,18 @@ def authorizer
282285 @authorizer ||= ::JSONAPI ::Authorization . configuration . authorizer . new ( context : context )
283286 end
284287
288+ def resources_from_relationship ( source_klass , source_id , relationship_type , context )
289+ rid = source_klass . find_related_fragments (
290+ [ JSONAPI ::ResourceIdentity . new ( source_klass , source_id ) ] ,
291+ relationship_type ,
292+ context : context
293+ ) . keys . first
294+
295+ return nil if rid . nil?
296+
297+ rid . resource_klass . find_to_populate_by_keys ( rid . id )
298+ end
299+
285300 # TODO: Communicate with upstream to fix this nasty hack
286301 def operation_resource_id
287302 case operation_type
0 commit comments