@@ -138,13 +138,15 @@ public ResourceObject GetData(ContextEntity contextEntity, IIdentifiable entity,
138
138
139
139
return data ;
140
140
}
141
- private bool ShouldIncludeAttribute ( AttrAttribute attr , object attributeValue )
141
+ private bool ShouldIncludeAttribute ( AttrAttribute attr , object attributeValue , RelationshipAttribute relationship = null )
142
142
{
143
143
return OmitNullValuedAttribute ( attr , attributeValue ) == false
144
144
&& attr . InternalAttributeName != nameof ( Identifiable . Id )
145
145
&& ( ( _jsonApiContext . QuerySet == null
146
146
|| _jsonApiContext . QuerySet . Fields . Count == 0 )
147
- || _jsonApiContext . QuerySet . Fields . Contains ( attr . InternalAttributeName ) ) ;
147
+ || _jsonApiContext . QuerySet . Fields . Contains ( relationship != null ?
148
+ $ "{ relationship . InternalRelationshipName } .{ attr . InternalAttributeName } " :
149
+ attr . InternalAttributeName ) ) ;
148
150
}
149
151
150
152
private bool OmitNullValuedAttribute ( AttrAttribute attr , object attributeValue )
@@ -225,13 +227,13 @@ private List<ResourceObject> IncludeRelationshipChain(
225
227
{
226
228
foreach ( IIdentifiable includedEntity in hasManyNavigationEntity )
227
229
{
228
- included = AddIncludedEntity ( included , includedEntity ) ;
230
+ included = AddIncludedEntity ( included , includedEntity , relationship ) ;
229
231
included = IncludeSingleResourceRelationships ( included , includedEntity , relationship , relationshipChain , relationshipChainIndex ) ;
230
232
}
231
233
}
232
234
else
233
235
{
234
- included = AddIncludedEntity ( included , ( IIdentifiable ) navigationEntity ) ;
236
+ included = AddIncludedEntity ( included , ( IIdentifiable ) navigationEntity , relationship ) ;
235
237
included = IncludeSingleResourceRelationships ( included , ( IIdentifiable ) navigationEntity , relationship , relationshipChain , relationshipChainIndex ) ;
236
238
}
237
239
@@ -254,9 +256,9 @@ private List<ResourceObject> IncludeSingleResourceRelationships(
254
256
}
255
257
256
258
257
- private List < ResourceObject > AddIncludedEntity ( List < ResourceObject > entities , IIdentifiable entity )
259
+ private List < ResourceObject > AddIncludedEntity ( List < ResourceObject > entities , IIdentifiable entity , RelationshipAttribute relationship )
258
260
{
259
- var includedEntity = GetIncludedEntity ( entity ) ;
261
+ var includedEntity = GetIncludedEntity ( entity , relationship ) ;
260
262
261
263
if ( entities == null )
262
264
entities = new List < ResourceObject > ( ) ;
@@ -270,7 +272,7 @@ private List<ResourceObject> AddIncludedEntity(List<ResourceObject> entities, II
270
272
return entities ;
271
273
}
272
274
273
- private ResourceObject GetIncludedEntity ( IIdentifiable entity )
275
+ private ResourceObject GetIncludedEntity ( IIdentifiable entity , RelationshipAttribute relationship )
274
276
{
275
277
if ( entity == null ) return null ;
276
278
@@ -281,13 +283,14 @@ private ResourceObject GetIncludedEntity(IIdentifiable entity)
281
283
282
284
data . Attributes = new Dictionary < string , object > ( ) ;
283
285
284
- foreach ( var attr in contextEntity . Attributes )
286
+ contextEntity . Attributes . ForEach ( attr =>
285
287
{
286
- if ( attr . InternalAttributeName == nameof ( Identifiable . Id ) )
287
- continue ;
288
-
289
- data . Attributes . Add ( attr . PublicAttributeName , attr . GetValue ( entity ) ) ;
290
- }
288
+ var attributeValue = attr . GetValue ( entity ) ;
289
+ if ( ShouldIncludeAttribute ( attr , attributeValue , relationship ) )
290
+ {
291
+ data . Attributes . Add ( attr . PublicAttributeName , attributeValue ) ;
292
+ }
293
+ } ) ;
291
294
292
295
return data ;
293
296
}
0 commit comments