# Two way collection link \[Feature/add-on request\]

**URL:** <https://discourse.getcockpit.com/t/two-way-collection-link-feature-add-on-request/858>\
**Category:** Feature Request\
**Created:** [June 7, 2019, 6:40pm UTC](https://discourse.getcockpit.com/t/two-way-collection-link-feature-add-on-request/858 "2019-06-07T18:40:52Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jasonday](https://avatars.discourse-cdn.com/v4/letter/j/67e7ee/32.png) [@jasonday](https://discourse.getcockpit.com/u/jasonday)\
**Post date:** [June 7, 2019, 6:40pm UTC](https://discourse.getcockpit.com/t/two-way-collection-link-feature-add-on-request/858/1 "2019-06-07T18:40:52Z")

</div>

Essentially the way I envision it working is that if you create a collection link within both collections, with some type of common identifier in the JSON attributes, and select collectionB.item2 from collectionA.item1, collectionB.item2 would show that it was linked from collectionA.item1.

This would build a two way relationship, which can be helpful. In my use case, I’m building a documentation site build of modules that have relationships to one another. I can do this currently, but it’s manual and not two-way. So if I make a change in the relationship, I have to make the change across multiple entries.

---

<div class="post-metadata">

**Author:** ![Blistok](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/blistok/32/212_2.png) [@Blistok](https://discourse.getcockpit.com/u/Blistok)\
**Post date:** [June 7, 2019, 6:48pm UTC](https://discourse.getcockpit.com/t/two-way-collection-link-feature-add-on-request/858/2 "2019-06-07T18:48:54Z")

</div>

Related:

> [@Two way collection link](https://discourse.getcockpit.com/t/two-way-collection-link/527):
>
> Hi, I’m looking for the way to have two way auto link for relationships. Collection-Link options seem to allow only for linking one way. So, if I have Author has\_many Books, and I create link to the author from each corresponding book, I would like on the authors entry to see list of all linked books. Thanks for the great work!

---

<div class="post-metadata">

**Author:** ![Blistok](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/blistok/32/212_2.png) [@Blistok](https://discourse.getcockpit.com/u/Blistok)\
**Post date:** [June 18, 2019, 5:23am UTC](https://discourse.getcockpit.com/t/two-way-collection-link-feature-add-on-request/858/3 "2019-06-18T05:23:24Z")

</div>

This is how laravel-mongo describes it:

> **[GitHub - mongodb/laravel-mongodb: A MongoDB based Eloquent model and Query...](https://github.com/mongodb/laravel-mongodb#embedsmany-relations)**
>
> A MongoDB based Eloquent model and Query builder for Laravel (Moloquent) - GitHub - mongodb/laravel-mongodb: A MongoDB based Eloquent model and Query builder for Laravel (Moloquent)

> The inverse relation is auto _magically_ available, you don’t need to define this reverse relation.
> 
> `$user = $book->user;`

---

<div class="post-metadata">

**Author:** ![jasonday](https://avatars.discourse-cdn.com/v4/letter/j/67e7ee/32.png) [@jasonday](https://discourse.getcockpit.com/u/jasonday)\
**Post date:** [August 4, 2020, 12:11am UTC](https://discourse.getcockpit.com/t/two-way-collection-link-feature-add-on-request/858/4 "2020-08-04T00:11:25Z")

</div>

Just bumping for visibility.

---

<div class="post-metadata">

**Author:** ![giulioscattolin](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/giulioscattolin/32/670_2.png) [@giulioscattolin](https://discourse.getcockpit.com/u/giulioscattolin)\
**Post date:** [August 21, 2020, 4:39pm UTC](https://discourse.getcockpit.com/t/two-way-collection-link-feature-add-on-request/858/5 "2020-08-21T16:39:34Z")

</div>

Hi Jason, my two cents here.

Create a `ModuleRelationships` collection that has two `collectionlink` fields that both link to the `Module` collection. Whenever two modules are related, add an item to that collection referencing the two modules (a module can even be related to itself under this scenario).

It does not matter which module goes to which field, it only matters how the relationship will be fetched. To retrieve all the modules related to a given module you can filter the `ModuleRelationships` collection for all the items that have one `collectionlink` field that references that particular module. Cockpit’s `filter` capabilities should support this nicely.

EDIT: In addition to this, if you click the `LINKED` button in the `Edit Entry` page while editing a module you can see which entries in the `ModuleRelationships` collection point to that module.
