# Reference embedded in object does not work

**URL:** <https://community.forestadmin.com/t/reference-embedded-in-object-does-not-work/1118>\
**Category:** Help me!\
**Created:** [October 13, 2020, 6:02am UTC](https://community.forestadmin.com/t/reference-embedded-in-object-does-not-work/1118 "2020-10-13T06:02:49Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![linsze](https://avatars.discourse-cdn.com/v4/letter/l/b487fb/32.png) [@linsze](https://community.forestadmin.com/u/linsze)\
**Post date:** [October 13, 2020, 6:02am UTC](https://community.forestadmin.com/t/reference-embedded-in-object-does-not-work/1118/1 "2020-10-13T06:02:49Z")

</div>

I’m trying to display “groups” where each element is an object containing a reference to “group” document.

![image](https://europe1.discourse-cdn.com/flex013/uploads/forest/original/1X/0f83a88e140e68dc9b89ff0229ec20e3274f896a.png)

## Expected behavior

Each group has an “\_id” field which links to the actual “group” document, with “pastSessionsCount” and “attendedSessionsCount”.

## Actual behavior

“\_id” field is empty without error messages in the console.

 ![image](https://europe1.discourse-cdn.com/flex013/uploads/forest/original/1X/b71928e79424bb929174344716b4bc0fe6ca27c2.png)

## Failure Logs

No failure logs are being displayed.

## Context

- Express Version: “~4.16.3”
- Database Type: “MongoDB”
- Project Name: “BTAttendanceSystem”

---

<div class="post-metadata">

**Author:** ![anon79585656](https://avatars.discourse-cdn.com/v4/letter/a/7ab992/32.png) [@anon79585656](https://community.forestadmin.com/u/anon79585656)\
**Post date:** [October 13, 2020, 10:11am UTC](https://community.forestadmin.com/t/reference-embedded-in-object-does-not-work/1118/2 "2020-10-13T10:11:30Z")

</div>

Hello @linsze and welcome to the Forest Admin community,

Given your code snippet, I think you already checked our documentation? [https://docs.forestadmin.com/documentation/reference-guide/relationships#adding-relationships](https://docs.forestadmin.com/documentation/reference-guide/relationships#adding-relationships)  
This might also help [https://mongoosejs.com/docs/guide.html](https://mongoosejs.com/docs/guide.html)

Could you share your model files for `groups` and the one using them?

---

<div class="post-metadata">

**Author:** ![linsze](https://avatars.discourse-cdn.com/v4/letter/l/b487fb/32.png) [@linsze](https://community.forestadmin.com/u/linsze)\
**Post date:** [October 13, 2020, 10:30am UTC](https://community.forestadmin.com/t/reference-embedded-in-object-does-not-work/1118/3 "2020-10-13T10:30:15Z")

</div>

> I think you already checked our documentation?  
> Yes I’ve already done that. It doesn’t seem to work the way I expect to be probably because it’s not a direct referencing.

> Could you share your model files for `groups` and the one using them?  
> The model file for “groups”:  
> ![image](https://europe1.discourse-cdn.com/flex013/uploads/forest/original/1X/8f4a638abdcb80a7aaa4c1dca117acbb325d690a.png)

The model file for “students”:  
 ![image](https://europe1.discourse-cdn.com/flex013/uploads/forest/original/1X/42c84c2c53d7b90ab43b78d3d2a383741f49c133.png)

---

<div class="post-metadata">

**Author:** ![anon79585656](https://avatars.discourse-cdn.com/v4/letter/a/7ab992/32.png) [@anon79585656](https://community.forestadmin.com/u/anon79585656)\
**Post date:** [October 13, 2020, 1:16pm UTC](https://community.forestadmin.com/t/reference-embedded-in-object-does-not-work/1118/4 "2020-10-13T13:16:33Z")

</div>

Would you mind trying to rename the second `_id` to something like `groups_id`? It might lead to a confusion with primary key reserved field name.

---

<div class="post-metadata">

**Author:** ![linsze](https://avatars.discourse-cdn.com/v4/letter/l/b487fb/32.png) [@linsze](https://community.forestadmin.com/u/linsze)\
**Post date:** [October 13, 2020, 1:37pm UTC](https://community.forestadmin.com/t/reference-embedded-in-object-does-not-work/1118/5 "2020-10-13T13:37:22Z")

</div>

I changed the first “\_id” to “group” and the columns are no longer empty. However, it is still not showing the link to the referenced group document.

 ![image](https://europe1.discourse-cdn.com/flex013/uploads/forest/original/1X/2c7d50f6c978264206a06e4f4765eabd11a54a48.png)

---

<div class="post-metadata">

**Author:** ![anon79585656](https://avatars.discourse-cdn.com/v4/letter/a/7ab992/32.png) [@anon79585656](https://community.forestadmin.com/u/anon79585656)\
**Post date:** [October 13, 2020, 1:41pm UTC](https://community.forestadmin.com/t/reference-embedded-in-object-does-not-work/1118/6 "2020-10-13T13:41:01Z")

</div>

Could you please retry with `group_id` and if not working `groups_id`? Naming could matter here when your models are analysed.

---

<div class="post-metadata">

**Author:** ![linsze](https://avatars.discourse-cdn.com/v4/letter/l/b487fb/32.png) [@linsze](https://community.forestadmin.com/u/linsze)\
**Post date:** [October 13, 2020, 1:50pm UTC](https://community.forestadmin.com/t/reference-embedded-in-object-does-not-work/1118/7 "2020-10-13T13:50:41Z")

</div>

Tried both and it’s still not working.

---

<div class="post-metadata">

**Author:** ![Guillaume\_Cisco](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/guillaume_cisco/32/918_2.png) [@Guillaume\_Cisco](https://community.forestadmin.com/u/Guillaume_Cisco)\
**Post date:** [October 14, 2020, 9:32am UTC](https://community.forestadmin.com/t/reference-embedded-in-object-does-not-work/1118/8 "2020-10-14T09:32:36Z")

</div>

Hello @linzse,

Embedded documents with references in mongo is not currently supported by Forest Admin. It will be addressed to our product team.  
[Classic HasMany (array of Object Id)](https://docs.forestadmin.com/documentation/reference-guide/relationships#hasmany-1) relationships are supported.  
For dealing with relationships, you will need to modify your schema for adding a related table dedicated to a `subscribed_group` model by user with its `pastSessionCount` and `attendedSessionCount` fields.

You can also use [smart relationships](https://docs.forestadmin.com/documentation/reference-guide/relationships/create-a-smart-relationship#creating-a-hasmany-smart-relationship) for this kind of issue.

---

<div class="post-metadata">

**Author:** ![linsze](https://avatars.discourse-cdn.com/v4/letter/l/b487fb/32.png) [@linsze](https://community.forestadmin.com/u/linsze)\
**Post date:** [October 14, 2020, 1:34pm UTC](https://community.forestadmin.com/t/reference-embedded-in-object-does-not-work/1118/9 "2020-10-14T13:34:50Z")

</div>

Hi, when I tried with smart relationships, the links to the referenced “group” were shown but pastSessionsCount and attendedSessionsCount disappeared. Do you have any suggestions to overcome this? I tried modifying the local models of a “group” to include those fields but it didn’t work since those fields do not exist in the actual “group” document in the database.

---

<div class="post-metadata">

**Author:** ![Guillaume\_Cisco](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/guillaume_cisco/32/918_2.png) [@Guillaume\_Cisco](https://community.forestadmin.com/u/Guillaume_Cisco)\
**Post date:** [October 14, 2020, 4:29pm UTC](https://community.forestadmin.com/t/reference-embedded-in-object-does-not-work/1118/10 "2020-10-14T16:29:31Z")

</div>

Hi @linsze,

How did you create your smart relationships?  
Maybe you can looks at [Managing nested documents in Mongoose](https://docs.forestadmin.com/documentation/reference-guide/models/enrich-your-models#managing-nested-documents-in-mongoose).

Let me know if it helps,
