# Custom Types Relationships

**URL:** https://community.prismic.io/t/custom-types-relationships/1431
**Category:** Developing with Prismic
**Created:** [August 4, 2020, 6:49pm UTC](https://community.prismic.io/t/custom-types-relationships/1431 "2020-08-04T18:49:32Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![fransy](https://avatars.discourse-cdn.com/v4/letter/f/4da419/32.png) [@fransy](https://community.prismic.io/u/fransy)
#### Post date: [August 4, 2020, 6:49pm UTC](https://community.prismic.io/t/custom-types-relationships/1431/1 "2020-08-04T18:49:32Z")

</div>

Hi, I would like to create a relationship or link between custom types. However, I would like that to be done in both sides. For instance, I have a custom type "category" and a custom type "article"  
I created the content relationship in the custom type "article"

I have  
Article 1: Category A and Category B  
Article 2: Category A

However I'd like to have the following automatically updated  
Category A: Article 1 and Article 2.

If articles get added or removed from a category then it will reflect in both the category and the articles

Is this something possible or in your roadmap?

Thank you!

---

<div class="post-metadata">

### Author: ![Fares](https://avatars.discourse-cdn.com/v4/letter/f/71e660/32.png) [@Fares](https://community.prismic.io/u/Fares)
#### Post date: [August 5, 2020, 12:48pm UTC](https://community.prismic.io/t/custom-types-relationships/1431/2 "2020-08-05T12:48:40Z")

</div>

Hi,  
Welcome to Prismic community, I will try to help you with this.

In order to be able to help you with this, may I know what is the exact use-case of what you are trying to achieve?

Best,  
Fares

---

<div class="post-metadata">

### Author: ![fransy](https://avatars.discourse-cdn.com/v4/letter/f/4da419/32.png) [@fransy](https://community.prismic.io/u/fransy)
#### Post date: [August 5, 2020, 1:46pm UTC](https://community.prismic.io/t/custom-types-relationships/1431/3 "2020-08-05T13:46:50Z")

</div>

Hi Fares,

Of course. Well, that is the exact user-case. Just to summarise it a little bit better:

I have the following custom types:

- Article
- Category
- Place

In prismic, the content editors will assign categories and places to each article. So an article can have multiple categories and multiple places.

I’ve added a “Content relationship” in the Article Custom Type and select the Category Custom type so this one is linked.  
Also, I’ve added another “Content relationship” in the Article custom type so it allows to select places.

**Example:**

Article 1 belongs to category A and category B  
Article 2 belongs to category A  
Article 1 is about place 1 and place 2

**In Prismic dashboard:**  
When editing an article, you can select multiple categories and multiple places.  
However, when editing a category you can’t really see what articles have been linked to the category.

_Question:_ is there a feature to see the articles linked to the category?

**In the front end, we will require:**  
case 1. A page for Article 1 that shows that it belongs to category A and category B  
case 2. A page for Category A that shows a list of articles, in this example Article 1 and Article 2  
case 3. A page for Place 1 that shows a list of articles it has been mentioned in. In this example, Article 1, and a list of Categories in this example Category A and Category B because they belong to the Article the place is linked to (Article 1)

Case 1 seems to be the easy one as the content relationship between category an article sits on the Article custom type.

_Question:_ Can you please help me to try to achieve case 2 without having to loop in all the articles and checking if they have category A linked to them?

Case 3 is tricky so for now, I’ll focus on case 1 and case 2

Thanks!

---

<div class="post-metadata">

### Author: ![Fares](https://avatars.discourse-cdn.com/v4/letter/f/71e660/32.png) [@Fares](https://community.prismic.io/u/Fares)
#### Post date: [October 2, 2020, 2:50pm UTC](https://community.prismic.io/t/custom-types-relationships/1431/18 "2020-10-02T14:50:00Z")

</div>

Hi Fransy,

If I understood correctly then here is how to do it:

- Case 2:

You will need to do 2 queries to achieve that, When you are in the Category page you get the UID from the Url and you fetch your Category X by it's UID

_Rest API:_

```auto
[at(my.category.uid, "CATEGORY-X-UID")]

```

Result:

 ![Screenshot 2020-10-02 at 12.39.28](https://europe1.discourse-cdn.com/flex013/uploads/prismic/original/1X/e544aeb2b1e4579153edd7de10fb2200b288e5a3.png)

Using the category Id returned you do your second query to fetch the list of Articles such as:

_Rest API:_

```auto
q = [[at(my.catergory.article_link,"WNje3SUAAEGBu8bc")]]

```

and to get all the articles linked to this category you can query articles by a content relationship that has that category id such as:

[at(my.article.category\_link,"X3b\_1hIAACMA-YWk")]

_JavaScript:_

```auto
api.query(Prismic.Predicates.at('my.article.category_link', 'WNje3SUAAEGBu8bc')).then(function(response) {
  // response is the response object, response.results holds the documents
});

```

Result:

 ![Screenshot 2020-10-02 at 12.39.40](https://europe1.discourse-cdn.com/flex013/uploads/prismic/original/1X/3c1c223420fb50eb803877e8e5a46477fb8e2082.png)

- Case 3:  
Case 3 is almost the same as case 2 except that you add another query to get the linked places.

You can read more about querying by content relationship in the [article](https://prismic.io/docs/javascript/query-the-api/query-by-content-relationship)

Hope that this answers your question,  
Fares

---

<div class="post-metadata">

### Author: ![Fares](https://avatars.discourse-cdn.com/v4/letter/f/71e660/32.png) [@Fares](https://community.prismic.io/u/Fares)
#### Post date: [October 15, 2020, 2:31pm UTC](https://community.prismic.io/t/custom-types-relationships/1431/19 "2020-10-15T14:31:55Z")

</div>

This issue has been closed due to inactivity. [Flag to reopen](https://community.prismic.io/t/re-open-a-thread/2175).

---

<div class="post-metadata">

### Author: ![system](https://dub1.discourse-cdn.com/flex013/user_avatar/community.prismic.io/system/32/1746_2.png) [@system](https://community.prismic.io/u/system)
#### Post date: [December 9, 2021, 12:08pm UTC](https://community.prismic.io/t/custom-types-relationships/1431/20 "2021-12-09T12:08:58Z")

</div>


