# Smart Relationships Not working

**URL:** <https://community.forestadmin.com/t/smart-relationships-not-working/4755>\
**Category:** Help me!\
**Tags:** dashboard\
**Created:** [June 3, 2022, 7:13am UTC](https://community.forestadmin.com/t/smart-relationships-not-working/4755 "2022-06-03T07:13:41Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![skdev24](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/skdev24/32/4007_2.png) [@skdev24](https://community.forestadmin.com/u/skdev24)\
**Post date:** [June 3, 2022, 7:13am UTC](https://community.forestadmin.com/t/smart-relationships-not-working/4755/1 "2022-06-03T07:13:41Z")

</div>

We have complex relationships between the two collections, i.e., “Companies” & “Consumers.”

**Companies schema**

```javascript
{
    ...
    'applicationId': String,
    'users': [{ type: Mongoose.Schema.Types.ObjectId, ref: 'consumers'}],
  }

```

**Consumer schema**

```javascript
{
    ...
    'applicationId': String,
  }

```

By just this much, I was not able to create the relationship then. I tried another method by adding this code to forest “companies” fields,

```javascript
{
      field: 'users',
      type: [Object],
      ref: 'consumers',
      reference: 'consumers.applicationId',
    }

```

Still, this didn’t solve then. I manually added the route for the APIs that forest was calling when getting all consumers for an application. Still, by doing this, when I navigated to consumers’ tabs, initially, all fields were empty.

 ![Screenshot 2022-06-02 at 10.58.02 AM](https://europe1.discourse-cdn.com/flex013/uploads/forest/original/2X/3/319220ca17c1ef23e69901a96be6ec9e4f021021.png)

---

<div class="post-metadata">

**Author:** ![GuillaumeGautreau](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/guillaumegautreau/32/557_2.png) [@GuillaumeGautreau](https://community.forestadmin.com/u/GuillaumeGautreau)\
**Post date:** [June 3, 2022, 11:18am UTC](https://community.forestadmin.com/t/smart-relationships-not-working/4755/3 "2022-06-03T11:18:14Z")

</div>

Hello @skdev24,

Can you please share with us the required info when creating a new community post?

> - Project name: …
> - Team name: …
> - Environment name: …
> - Agent type & version: …
> - Recent changes made on your end if any: …

This will give us context about your project, and help us identify the issue.

As it seems that you’re not referencing the document id from `companies`, I suggest you to create a smart relationship as [explained here in the docs](https://docs.forestadmin.com/documentation/reference-guide/models/relationships/create-a-smart-relationship).

This way you’ll be able to make it work properly.

---

<div class="post-metadata">

**Author:** ![skdev24](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/skdev24/32/4007_2.png) [@skdev24](https://community.forestadmin.com/u/skdev24)\
**Post date:** [June 6, 2022, 11:46am UTC](https://community.forestadmin.com/t/smart-relationships-not-working/4755/4 "2022-06-06T11:46:10Z")

</div>

Hey @GuillaumeGautreau,

Thanks for the advice [routes/product.js](https://docs.forestadmin.com/documentation/reference-guide/models/relationships/create-a-smart-relationship#creating-a-hasmany-smart-relationship) file did help in connecting two collections with different reference keys.
