Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
5f3e04b
refactor: AttachHasOnePointers
maurei Jun 7, 2019
e8d1096
refactor: AssignHasMany pointers
maurei Jun 7, 2019
1420d6d
refactor assign relationships and applied to updateasync method
maurei Jun 7, 2019
24dd97c
refactor: tests passing again
maurei Jun 7, 2019
0304725
test: add implicit removal test
maurei Jun 7, 2019
f60587f
test: all passing
maurei Jun 7, 2019
4cd9465
chore: addedd notes wrt implicit remove
maurei Jun 7, 2019
d1f39e6
comments: added comment to assign method
maurei Jun 7, 2019
bcbf8c3
Merge branch 'master' into fix/reattachment
maurei Jun 7, 2019
7df5233
fix: support for entity resource split
maurei Jun 7, 2019
0296eb4
fix: minor refactor, comments
maurei Jun 8, 2019
f0d5924
fix: foreignkey set null bug
maurei Jun 8, 2019
9f7550c
feat: decoupled repository from JsonApiContext with respect to updati…
maurei Jun 11, 2019
7aea60c
feat: decoupled IJsonApiContext from repository wrt updating resources
maurei Jun 11, 2019
652d65f
fix: resource separation issue|
maurei Jun 11, 2019
9838627
chore: cherry picked inverse relationships from hooks branch
maurei Jun 11, 2019
fbe69fc
fix: tests
maurei Jun 11, 2019
35a2f54
feat: implicit remove support
maurei Jun 11, 2019
6e6f7fa
fix: test
maurei Jun 11, 2019
c1d472d
fix: bugs with inverse relationship loading
maurei Jun 11, 2019
f45972f
tests: implicit remove through create tests
maurei Jun 11, 2019
d8b4217
feat: mark obsolete UpdateAsync(TId id, TEntity entity) method, add n…
maurei Jun 11, 2019
30765c3
fix: #520
maurei Jun 11, 2019
9139852
fix: separation tests
maurei Jun 11, 2019
457e93d
chore: comments
maurei Jun 12, 2019
65f8a3a
Update DefaultEntityRepository.cs
maurei Jun 12, 2019
3ddb6a2
Update DefaultEntityRepository.cs
maurei Jun 17, 2019
2437077
Update TypeExtensions.cs
maurei Jun 17, 2019
415306e
Update DefaultEntityRepository.cs
maurei Jun 17, 2019
52a452d
Update JsonApiReader.cs
maurei Jun 17, 2019
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
comments: added comment to assign method
  • Loading branch information
maurei committed Jun 7, 2019
commit d1f39e6ac8dfc0ca0b31173b35cf2d48975d9c73
42 changes: 21 additions & 21 deletions src/JsonApiDotNetCore/Data/DefaultEntityRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,6 @@ public void DetachRelationshipPointers(TEntity entity)
}
}




/// <inheritdoc />
public virtual async Task<TEntity> UpdateAsync(TId id, TEntity entity)
{
Expand Down Expand Up @@ -247,12 +244,12 @@ public virtual async Task<TEntity> UpdateAsync(TId id, TEntity entity)
{
// load relations to enforce complete replace
await _context.Entry(oldEntity).Collection(hasManyAttribute.InternalRelationshipName).LoadAsync();
// also need to load inverse relationship here, see issue #502
// todo: need to load inverse relationship here, see issue #502
hasManyAttribute.SetValue(oldEntity, relationshipValue);
}
else if (relationshipEntry.Key is HasOneAttribute hasOneAttribute)
{
// need to load inverse relationship here, see issue #502
// todo: need to load inverse relationship here, see issue #502
hasOneAttribute.SetValue(oldEntity, relationshipValue);
}
}
Expand All @@ -261,22 +258,6 @@ public virtual async Task<TEntity> UpdateAsync(TId id, TEntity entity)
return oldEntity;
}

private void AssignHasManyThrough(TEntity entity, HasManyThroughAttribute hasManyThrough, IList relationshipValue)
{
var pointers = relationshipValue.Cast<IIdentifiable>();
var throughRelationshipCollection = Activator.CreateInstance(hasManyThrough.ThroughProperty.PropertyType) as IList;
hasManyThrough.ThroughProperty.SetValue(entity, throughRelationshipCollection);

foreach (var pointer in pointers)
{
var throughInstance = Activator.CreateInstance(hasManyThrough.ThroughType);
hasManyThrough.LeftProperty.SetValue(throughInstance, entity);
hasManyThrough.RightProperty.SetValue(throughInstance, pointer);
throughRelationshipCollection.Add(throughInstance);
}
}


/// <inheritdoc />
public async Task UpdateRelationshipsAsync(object parent, RelationshipAttribute relationship, IEnumerable<string> relationshipIds)
{
Expand Down Expand Up @@ -422,7 +403,26 @@ private void AttachHasManyAndHasManyThroughPointers(TEntity entity)
}
}

/// <summary>
/// The relationshipValue parameter contains the dependent side of the relationship (Tags).
/// We can't directly add them to the principal entity (Article): we need to
/// use the join table (ArticleTags). This methods assigns the relationship value to entity
/// by taking care of that
/// </summary>
protected void AssignHasManyThrough(TEntity entity, HasManyThroughAttribute hasManyThrough, IList relationshipValue)
{
var pointers = relationshipValue.Cast<IIdentifiable>();
var throughRelationshipCollection = Activator.CreateInstance(hasManyThrough.ThroughProperty.PropertyType) as IList;
hasManyThrough.ThroughProperty.SetValue(entity, throughRelationshipCollection);

foreach (var pointer in pointers)
{
var throughInstance = Activator.CreateInstance(hasManyThrough.ThroughType);
hasManyThrough.LeftProperty.SetValue(throughInstance, entity);
hasManyThrough.RightProperty.SetValue(throughInstance, pointer);
throughRelationshipCollection.Add(throughInstance);
}
}

/// <summary>
/// This is used to allow creation of HasOne relationships when the
Expand Down