# How to get the list of entities in an relation field?

**URL:** <https://community.fibery.io/t/how-to-get-the-list-of-entities-in-an-relation-field/8218>\
**Category:** Get Help\
**Created:** [February 5, 2025, 9:55am UTC](https://community.fibery.io/t/how-to-get-the-list-of-entities-in-an-relation-field/8218 "2025-02-05T09:55:25Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ooker](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/ooker/32/7033_2.png) [@Ooker](https://community.fibery.io/u/Ooker)\
**Post date:** [February 5, 2025, 9:55am UTC](https://community.fibery.io/t/how-to-get-the-list-of-entities-in-an-relation-field/8218/1 "2025-02-05T09:55:26Z")

</div>

In a same space I have to database A and B. A has a one-to-many to B and B has a one-to-one to A. When a trigger happens in an entity of A, I want to get the list of all entities of B related to it, filter some of them and delete the rest. I try log an entity of A from `args.currentEntities`, but I don’t see the field B. But I can see field A when I log an entity of B. Why is that?

---

<div class="post-metadata">

**Author:** ![Chr1sG](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/chr1sg/32/3941_2.png) [@Chr1sG](https://community.fibery.io/u/Chr1sG)\
**Post date:** [February 5, 2025, 10:16am UTC](https://community.fibery.io/t/how-to-get-the-list-of-entities-in-an-relation-field/8218/2 "2025-02-05T10:16:38Z")

</div>

> [@Ooker](#):
>
> A has a one-to-many to B and B has a one-to-one to A.

Do you mean that there are two relations?  
Or do you mean a single relation, such that A can link to many Bs, but each B can only link to one A?

Assuming the latter, when you have a button/rule in the A database, then the linked B items will be available via `[Step 1 A].[Bs]` (assuming the field in db A for linked Bs is called `Bs`)

If you want to change which B entities are linked to A (to only be a subset of those currently linked) then you can use the update action, choose field `Bs` to be updated, and use a formula, e.g.  
`[Step 1 A].[Bs].Filter(X = Y)`

---

<div class="post-metadata">

**Author:** ![Ooker](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/ooker/32/7033_2.png) [@Ooker](https://community.fibery.io/u/Ooker)\
**Post date:** [February 5, 2025, 3:22pm UTC](https://community.fibery.io/t/how-to-get-the-list-of-entities-in-an-relation-field/8218/3 "2025-02-05T15:22:18Z")

</div>

I create the relation in db B and in A the reference of B shown up, so I guess it’s a single relation.

I’m using rule and writing script. I don’t know where the formula locates. Can you give me a screenshot?

---

<div class="post-metadata">

**Author:** ![Chr1sG](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/chr1sg/32/3941_2.png) [@Chr1sG](https://community.fibery.io/u/Chr1sG)\
**Post date:** [February 5, 2025, 3:34pm UTC](https://community.fibery.io/t/how-to-get-the-list-of-entities-in-an-relation-field/8218/4 "2025-02-05T15:34:47Z")

</div>

> [@Ooker](#):
>
> I’m using rule and writing script.

You shouldn’t need to use a script.

 ![image](https://us1.discourse-cdn.com/flex020/uploads/fibery/original/2X/d/d705820713fea2cded2ed9bca54dc5bfa4f9e52a.png)

[https://the.fibery.io/@public/User\_Guide/Guide/Add-Formula-to-Automation-Button-211/anchor=How-to-add-a-formula-into-Action--36e31ec5-3383-4613-8212-d2587d88a8e5](https://the.fibery.io/@public/User_Guide/Guide/Add-Formula-to-Automation-Button-211/anchor=How-to-add-a-formula-into-Action--36e31ec5-3383-4613-8212-d2587d88a8e5)

(the guide applies to buttons and rules equally)

---

<div class="post-metadata">

**Author:** ![Ooker](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/ooker/32/7033_2.png) [@Ooker](https://community.fibery.io/u/Ooker)\
**Post date:** [February 5, 2025, 3:46pm UTC](https://community.fibery.io/t/how-to-get-the-list-of-entities-in-an-relation-field/8218/5 "2025-02-05T15:46:23Z")

</div>

Hmm, as I have already written a complicated script, I want to manage everything in one place. Plus that I can control the data better. Is there a way to make it a script?

---

<div class="post-metadata">

**Author:** ![Chr1sG](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/chr1sg/32/3941_2.png) [@Chr1sG](https://community.fibery.io/u/Chr1sG)\
**Post date:** [February 5, 2025, 4:21pm UTC](https://community.fibery.io/t/how-to-get-the-list-of-entities-in-an-relation-field/8218/6 "2025-02-05T16:21:14Z")

</div>

If you’re insistent on using a script, then you will have to use `args.currentEntities` to get the A entity, and then use `getEntityById` to explicitly get its related Bs.

> [@Ooker](#):
>
> I try log an entity of A from `args.currentEntities`, but I don’t see the field B. But I can see field A when I log an entity of B. Why is that?

When you get an entity object, by default, only the primitive fields and any to-one relations are included in the fields returned. If you want to get the collection fields (to-many relations) you have to query specifically for them.

---

<div class="post-metadata">

**Author:** ![Ooker](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/ooker/32/7033_2.png) [@Ooker](https://community.fibery.io/u/Ooker)\
**Post date:** [February 5, 2025, 4:29pm UTC](https://community.fibery.io/t/how-to-get-the-list-of-entities-in-an-relation-field/8218/7 "2025-02-05T16:29:02Z")

</div>

> [@Chr1sG](#):
>
> use `getEntityById` to explicitly get its related Bs.

Does that mean that I need to store the IDs of the B entities locally in order to be able to query them?

---

<div class="post-metadata">

**Author:** ![Chr1sG](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/chr1sg/32/3941_2.png) [@Chr1sG](https://community.fibery.io/u/Chr1sG)\
**Post date:** [February 5, 2025, 4:33pm UTC](https://community.fibery.io/t/how-to-get-the-list-of-entities-in-an-relation-field/8218/8 "2025-02-05T16:33:57Z")

</div>

> [@Ooker](#):
>
> Does that mean that I need to store the IDs of the B entities locally in order to be able to query them?

Not sure what you mean by ‘storing IDs locally’.  
In general, your script will need to get A (using `args.currentEntities`) and then get the B IDs (using `getEntityById` on the A entity) and then if you then want to filter the Bs in some way, you may need to query them further (using `getEntitiesById` on the array of B IDs).  
So I suppose you could call that ‘storing IDs’

---

<div class="post-metadata">

**Author:** ![Ooker](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/ooker/32/7033_2.png) [@Ooker](https://community.fibery.io/u/Ooker)\
**Post date:** [February 5, 2025, 4:41pm UTC](https://community.fibery.io/t/how-to-get-the-list-of-entities-in-an-relation-field/8218/9 "2025-02-05T16:41:12Z")

</div>

Thanks. Somehow I mix up `args.currentEntities` with `fibery.getEntityById` 😅

> [@Chr1sG](#):
>
> When you get an entity object, by default, only the primitive fields and any to-one relations are included in the fields returned. If you want to get the collection fields (to-many relations) you have to query specifically for them.

Is there any reason behind this decision?

---

<div class="post-metadata">

**Author:** ![Chr1sG](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/chr1sg/32/3941_2.png) [@Chr1sG](https://community.fibery.io/u/Chr1sG)\
**Post date:** [February 5, 2025, 4:51pm UTC](https://community.fibery.io/t/how-to-get-the-list-of-entities-in-an-relation-field/8218/10 "2025-02-05T16:51:59Z")

</div>

> [@Ooker](#):
>
> > [@Chr1sG](#):
> >
> > When you get an entity object, by default, only the primitive fields and any to-one relations are included in the fields returned. If you want to get the collection fields (to-many relations) you have to query specifically for them.
> 
> Is there any reason behind this decision?

I suppose because there has to be a limit drawn somewhere as to what gets returned when you query an entity, to avoid the query taking too long

---

<div class="post-metadata">

**Author:** ![Chr1sG](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/chr1sg/32/3941_2.png) [@Chr1sG](https://community.fibery.io/u/Chr1sG)\
**Post date:** [April 29, 2025, 11:31am UTC](https://community.fibery.io/t/how-to-get-the-list-of-entities-in-an-relation-field/8218/11 "2025-04-29T11:31:00Z")

</div>


