@@ -156,7 +156,7 @@ private async Task<TResource> GetPrimaryResourceById(TId id, bool allowTopSparse
156
156
var primaryLayer = _queryLayerComposer . Compose ( _request . PrimaryResource ) ;
157
157
primaryLayer . Sort = null ;
158
158
primaryLayer . Pagination = null ;
159
- primaryLayer . Filter = CreateFilterById ( id ) ;
159
+ primaryLayer . Filter = IncludeFilterById ( id , primaryLayer . Filter ) ;
160
160
161
161
if ( ! allowTopSparseFieldSet && primaryLayer . Projection != null )
162
162
{
@@ -176,12 +176,16 @@ private async Task<TResource> GetPrimaryResourceById(TId id, bool allowTopSparse
176
176
return primaryResource ;
177
177
}
178
178
179
- private FilterExpression CreateFilterById ( TId id )
179
+ private FilterExpression IncludeFilterById ( TId id , FilterExpression existingFilter )
180
180
{
181
181
var primaryIdAttribute = _request . PrimaryResource . Attributes . Single ( a => a . Property . Name == nameof ( Identifiable . Id ) ) ;
182
182
183
- return new ComparisonExpression ( ComparisonOperator . Equals ,
183
+ FilterExpression filterById = new ComparisonExpression ( ComparisonOperator . Equals ,
184
184
new ResourceFieldChainExpression ( primaryIdAttribute ) , new LiteralConstantExpression ( id . ToString ( ) ) ) ;
185
+
186
+ return existingFilter == null
187
+ ? filterById
188
+ : new LogicalExpression ( LogicalOperator . And , new [ ] { filterById , existingFilter } ) ;
185
189
}
186
190
187
191
/// <inheritdoc />
@@ -279,12 +283,15 @@ public virtual async Task<TResource> UpdateAsync(TId id, TResource requestResour
279
283
// triggered by PATCH /articles/1/relationships/{relationshipName}
280
284
public virtual async Task UpdateRelationshipAsync ( TId id , string relationshipName , object relationships )
281
285
{
282
- _traceWriter . LogMethodStart ( new { id , relationshipName , related = relationships } ) ;
286
+ _traceWriter . LogMethodStart ( new { id , relationshipName , relationships } ) ;
283
287
if ( relationshipName == null ) throw new ArgumentNullException ( nameof ( relationshipName ) ) ;
284
288
285
289
AssertRelationshipExists ( relationshipName ) ;
286
290
287
291
var secondaryLayer = _queryLayerComposer . Compose ( _request . SecondaryResource ) ;
292
+ secondaryLayer . Projection = _queryLayerComposer . GetSecondaryProjectionForRelationshipEndpoint ( _request . SecondaryResource ) ;
293
+ secondaryLayer . Include = null ;
294
+
288
295
var primaryLayer = _queryLayerComposer . WrapLayerForSecondaryEndpoint ( secondaryLayer , _request . PrimaryResource , id , _request . Relationship ) ;
289
296
primaryLayer . Projection = null ;
290
297
@@ -306,7 +313,7 @@ public virtual async Task UpdateRelationshipAsync(TId id, string relationshipNam
306
313
: ( ( IEnumerable < IIdentifiable > ) relationships ) . Select ( e => e . StringId ) . ToArray ( ) ;
307
314
}
308
315
309
- await _repository . UpdateRelationshipsAsync ( primaryResource , _request . Relationship , relationshipIds ?? Array . Empty < string > ( ) ) ;
316
+ await _repository . UpdateRelationshipAsync ( primaryResource , _request . Relationship , relationshipIds ?? Array . Empty < string > ( ) ) ;
310
317
311
318
if ( _hookExecutor != null && primaryResource != null )
312
319
{
0 commit comments