Skip to content

Commit 0e04bea

Browse files
author
Bart Koelman
committed
Restored docs for HasManyThrough, which was removed in #1037
1 parent 6d7eeff commit 0e04bea

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

docs/usage/resources/relationships.md

+26
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,32 @@ public class Person : Identifiable
3434

3535
The left side of this relationship is of type `Person` (public name: "persons") and the right side is of type `TodoItem` (public name: "todoItems").
3636

37+
## HasManyThrough
38+
39+
_removed since v5.0_
40+
41+
Earlier versions of Entity Framework Core (up to v5) [did not support](https://github.com/aspnet/EntityFrameworkCore/issues/1368) many-to-many relationships without a join entity.
42+
For this reason, earlier versions of JsonApiDotNetCore filled this gap by allowing applications to declare a relationship as `HasManyThrough`,
43+
which would expose the relationship to the client the same way as any other `HasMany` relationship.
44+
However, under the covers it would use the join type and Entity Framework Core's APIs to get and set the relationship.
45+
46+
```c#
47+
public class Article : Identifiable
48+
{
49+
// tells Entity Framework Core to ignore this property
50+
[NotMapped]
51+
52+
// tells JsonApiDotNetCore to use the join table below
53+
[HasManyThrough(nameof(ArticleTags))]
54+
public ICollection<Tag> Tags { get; set; }
55+
56+
// this is the Entity Framework Core navigation to the join table
57+
public ICollection<ArticleTag> ArticleTags { get; set; }
58+
}
59+
```
60+
61+
The left side of this relationship is of type `Article` (public name: "articles") and the right side is of type `Tag` (public name: "tags").
62+
3763
## Name
3864

3965
There are two ways the exposed relationship name is determined:

0 commit comments

Comments
 (0)