@@ -215,9 +215,6 @@ public void DetachRelationshipPointers(TEntity entity)
215
215
}
216
216
}
217
217
218
-
219
-
220
-
221
218
/// <inheritdoc />
222
219
public virtual async Task < TEntity > UpdateAsync ( TId id , TEntity entity )
223
220
{
@@ -247,12 +244,12 @@ public virtual async Task<TEntity> UpdateAsync(TId id, TEntity entity)
247
244
{
248
245
// load relations to enforce complete replace
249
246
await _context . Entry ( oldEntity ) . Collection ( hasManyAttribute . InternalRelationshipName ) . LoadAsync ( ) ;
250
- // also need to load inverse relationship here, see issue #502
247
+ // todo: need to load inverse relationship here, see issue #502
251
248
hasManyAttribute . SetValue ( oldEntity , relationshipValue ) ;
252
249
}
253
250
else if ( relationshipEntry . Key is HasOneAttribute hasOneAttribute )
254
251
{
255
- // need to load inverse relationship here, see issue #502
252
+ // todo: need to load inverse relationship here, see issue #502
256
253
hasOneAttribute . SetValue ( oldEntity , relationshipValue ) ;
257
254
}
258
255
}
@@ -261,22 +258,6 @@ public virtual async Task<TEntity> UpdateAsync(TId id, TEntity entity)
261
258
return oldEntity ;
262
259
}
263
260
264
- private void AssignHasManyThrough ( TEntity entity , HasManyThroughAttribute hasManyThrough , IList relationshipValue )
265
- {
266
- var pointers = relationshipValue . Cast < IIdentifiable > ( ) ;
267
- var throughRelationshipCollection = Activator . CreateInstance ( hasManyThrough . ThroughProperty . PropertyType ) as IList ;
268
- hasManyThrough . ThroughProperty . SetValue ( entity , throughRelationshipCollection ) ;
269
-
270
- foreach ( var pointer in pointers )
271
- {
272
- var throughInstance = Activator . CreateInstance ( hasManyThrough . ThroughType ) ;
273
- hasManyThrough . LeftProperty . SetValue ( throughInstance , entity ) ;
274
- hasManyThrough . RightProperty . SetValue ( throughInstance , pointer ) ;
275
- throughRelationshipCollection . Add ( throughInstance ) ;
276
- }
277
- }
278
-
279
-
280
261
/// <inheritdoc />
281
262
public async Task UpdateRelationshipsAsync ( object parent , RelationshipAttribute relationship , IEnumerable < string > relationshipIds )
282
263
{
@@ -422,7 +403,26 @@ private void AttachHasManyAndHasManyThroughPointers(TEntity entity)
422
403
}
423
404
}
424
405
406
+ /// <summary>
407
+ /// The relationshipValue parameter contains the dependent side of the relationship (Tags).
408
+ /// We can't directly add them to the principal entity (Article): we need to
409
+ /// use the join table (ArticleTags). This methods assigns the relationship value to entity
410
+ /// by taking care of that
411
+ /// </summary>
412
+ protected void AssignHasManyThrough ( TEntity entity , HasManyThroughAttribute hasManyThrough , IList relationshipValue )
413
+ {
414
+ var pointers = relationshipValue . Cast < IIdentifiable > ( ) ;
415
+ var throughRelationshipCollection = Activator . CreateInstance ( hasManyThrough . ThroughProperty . PropertyType ) as IList ;
416
+ hasManyThrough . ThroughProperty . SetValue ( entity , throughRelationshipCollection ) ;
425
417
418
+ foreach ( var pointer in pointers )
419
+ {
420
+ var throughInstance = Activator . CreateInstance ( hasManyThrough . ThroughType ) ;
421
+ hasManyThrough . LeftProperty . SetValue ( throughInstance , entity ) ;
422
+ hasManyThrough . RightProperty . SetValue ( throughInstance , pointer ) ;
423
+ throughRelationshipCollection . Add ( throughInstance ) ;
424
+ }
425
+ }
426
426
427
427
/// <summary>
428
428
/// This is used to allow creation of HasOne relationships when the
0 commit comments