# Relationship data not populate under the related data

**URL:** <https://community.forestadmin.com/t/relationship-data-not-populate-under-the-related-data/2722>\
**Category:** Help me!\
**Created:** [June 17, 2021, 4:07pm UTC](https://community.forestadmin.com/t/relationship-data-not-populate-under-the-related-data/2722 "2021-06-17T16:07:41Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![sourabht](https://avatars.discourse-cdn.com/v4/letter/s/8491ac/32.png) [@sourabht](https://community.forestadmin.com/u/sourabht)\
**Post date:** [June 17, 2021, 4:07pm UTC](https://community.forestadmin.com/t/relationship-data-not-populate-under-the-related-data/2722/1 "2021-06-17T16:07:42Z")

</div>

Hi Team,

I have created the relationship between the user and the project entity.

I want to populate the projects under the specific user.

user model:

```javascript
...
'project': [{ type: Mongoose.Schema.Types.ObjectId, ref: 'projects' }],
...

```

When we are running our app it gives us empty results but multiple projects associated with user.

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

Thanks,  
Sourabh Turkar

---

<div class="post-metadata">

**Author:** ![anon34731316](https://avatars.discourse-cdn.com/v4/letter/a/eada6e/32.png) [@anon34731316](https://community.forestadmin.com/u/anon34731316)\
**Post date:** [June 18, 2021, 8:06am UTC](https://community.forestadmin.com/t/relationship-data-not-populate-under-the-related-data/2722/2 "2021-06-18T08:06:33Z")

</div>

Hello @sourabht,

Thanks for reaching out.

To help you out, could you please:

- Show me if you have any error when starting your server? And in your browser when accessing this related data?
- Give me the full user and projects models?

Thanks 🙌

---

<div class="post-metadata">

**Author:** ![sourabht](https://avatars.discourse-cdn.com/v4/letter/s/8491ac/32.png) [@sourabht](https://community.forestadmin.com/u/sourabht)\
**Post date:** [June 18, 2021, 11:53am UTC](https://community.forestadmin.com/t/relationship-data-not-populate-under-the-related-data/2722/3 "2021-06-18T11:53:13Z")

</div>

Hello @anon34731316 ,

I have the user model and project model.I need to display list of projects under the users module.

User model defined relationship into forest admin codebase. added below code manually after the lumber update.

```javascript
module.exports = (mongoose, Mongoose) => {
  // This section contains the properties of your model, mapped to your collection's properties.
  // Learn more here: https://docs.forestadmin.com/documentation/v/v6/reference-guide/models/enrich-your-models#declaring-a-new-field-in-a-model
  const schema = Mongoose.Schema({
    'status': Boolean,
    'first_name': String,
    'project': [{ type: Mongoose.Schema.Types.ObjectId, ref: 'projects' }],
  }, {
    timestamps: false,
  });

  return mongoose.model('users', schema, 'users');
};

```

in project model user has.

```javascript

module.exports = (mongoose, Mongoose) => {
  // This section contains the properties of your model, mapped to your collection's properties.
  // Learn more here: https://docs.forestadmin.com/documentation/v/v6/reference-guide/models/enrich-your-models#declaring-a-new-field-in-a-model
  const schema = Mongoose.Schema({
    'user': { type: Mongoose.Schema.Types.ObjectId, ref: 'users' },
    'project_name': String,
    'slug': String,
    'created_at': Date,
    'client_name': String,
    'cover_image_url': String,
    'updated_at': Date,
  }, {
    timestamps: false,
  });

  return mongoose.model('projects', schema, 'projects');
};

```

I need projects as related data under the user but it is showing the blank result as I mentioned above post screenshot.

Thanks,  
Sourabh

---

<div class="post-metadata">

**Author:** ![anon34731316](https://avatars.discourse-cdn.com/v4/letter/a/eada6e/32.png) [@anon34731316](https://community.forestadmin.com/u/anon34731316)\
**Post date:** [June 18, 2021, 12:46pm UTC](https://community.forestadmin.com/t/relationship-data-not-populate-under-the-related-data/2722/4 "2021-06-18T12:46:32Z")

</div>

@sourabht,

Why do you refer sometimes to `gigprojects` and sometimes to `projects`?  
The issue might come from here 🤔

---

<div class="post-metadata">

**Author:** ![sourabht](https://avatars.discourse-cdn.com/v4/letter/s/8491ac/32.png) [@sourabht](https://community.forestadmin.com/u/sourabht)\
**Post date:** [June 18, 2021, 12:48pm UTC](https://community.forestadmin.com/t/relationship-data-not-populate-under-the-related-data/2722/5 "2021-06-18T12:48:14Z")

</div>

@anon34731316 ,

I corrected that above post please refer to that. this is only projects.

Thanks,  
Sourabh

---

<div class="post-metadata">

**Author:** ![Arnaud\_Moncel](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/arnaud_moncel/32/24_2.png) [@Arnaud\_Moncel](https://community.forestadmin.com/u/Arnaud_Moncel)\
**Post date:** [June 18, 2021, 1:04pm UTC](https://community.forestadmin.com/t/relationship-data-not-populate-under-the-related-data/2722/6 "2021-06-18T13:04:51Z")

</div>

Hi @sourabht 👋 have you override the `/forest/users/:userId/relationships/projects` route?

---

<div class="post-metadata">

**Author:** ![sourabht](https://avatars.discourse-cdn.com/v4/letter/s/8491ac/32.png) [@sourabht](https://community.forestadmin.com/u/sourabht)\
**Post date:** [June 18, 2021, 1:46pm UTC](https://community.forestadmin.com/t/relationship-data-not-populate-under-the-related-data/2722/7 "2021-06-18T13:46:10Z")

</div>

> [@Arnaud\_Moncel](#):
>
> /forest/users/:userId/relationships/projects

No can you please help me on this.

---

<div class="post-metadata">

**Author:** ![Arnaud\_Moncel](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/arnaud_moncel/32/24_2.png) [@Arnaud\_Moncel](https://community.forestadmin.com/u/Arnaud_Moncel)\
**Post date:** [June 18, 2021, 1:51pm UTC](https://community.forestadmin.com/t/relationship-data-not-populate-under-the-related-data/2722/8 "2021-06-18T13:51:41Z")

</div>

In order to try to reproduce your issue, which is the version of `forest-express-mongoose`?

---

<div class="post-metadata">

**Author:** ![sourabht](https://avatars.discourse-cdn.com/v4/letter/s/8491ac/32.png) [@sourabht](https://community.forestadmin.com/u/sourabht)\
**Post date:** [June 18, 2021, 1:53pm UTC](https://community.forestadmin.com/t/relationship-data-not-populate-under-the-related-data/2722/9 "2021-06-18T13:53:08Z")

</div>

> [@Arnaud\_Moncel](#):
>
> forest-express-mongoose

forest-express-mongoose version is 7.0.0

---

<div class="post-metadata">

**Author:** ![Arnaud\_Moncel](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/arnaud_moncel/32/24_2.png) [@Arnaud\_Moncel](https://community.forestadmin.com/u/Arnaud_Moncel)\
**Post date:** [June 18, 2021, 2:44pm UTC](https://community.forestadmin.com/t/relationship-data-not-populate-under-the-related-data/2722/10 "2021-06-18T14:44:16Z")

</div>

If you do a manual find on your model you try to access what is the result?  
Have you got a project array?

```javascript
users.findById('yourId')
.then(user => {
  console.log(user);
});

```

Can you share with us the related field in your `.forestadmin-schema.json`  
exemple:

```json
{
    "field": "actors",
    "type": ["String"],
    "defaultValue": null,
    "enums": null,
    "integration": null,
    "isFilterable": true,
    "isPrimaryKey": false,
    "isReadOnly": false,
    "isRequired": false,
    "isSortable": true,
    "isVirtual": false,
    "reference": "persons._id",
    "inverseOf": null,
    "validations": []
  }

```

---

<div class="post-metadata">

**Author:** ![sourabht](https://avatars.discourse-cdn.com/v4/letter/s/8491ac/32.png) [@sourabht](https://community.forestadmin.com/u/sourabht)\
**Post date:** [June 18, 2021, 4:05pm UTC](https://community.forestadmin.com/t/relationship-data-not-populate-under-the-related-data/2722/11 "2021-06-18T16:05:06Z")

</div>

Hi @Arnaud_Moncel ,

below is the log of user

```javascript
{
  industry: [],
  project: [],
  _id: 60c9b592c99589172f73fc6f,
  first_name: 'Nedra',
  last_name: 'Sauer',
  created_at: 2021-06-16T08:25:55.093Z,
  updated_at: 2021-06-16T08:25:55.093Z,
  slug: 'nedra-sauer',
  __v: 0
}

```

project is null but the user is associated with a particular user. In my database.

What should i need to do here to make the association between users and projects?

the issue already debug with @louis on call.

Thanks,  
Sourabh

---

<div class="post-metadata">

**Author:** ![anon36130554](https://avatars.discourse-cdn.com/v4/letter/a/b3f665/32.png) [@anon36130554](https://community.forestadmin.com/u/anon36130554)\
**Post date:** [June 21, 2021, 3:00pm UTC](https://community.forestadmin.com/t/relationship-data-not-populate-under-the-related-data/2722/12 "2021-06-21T15:00:15Z")

</div>

Hello @sourabht 👋

Thanks for posting the logs it’s clear now 😃

As you can see, the user you posted does not have projects associated to him. In the project record associated to your user, the attribute `project.user` is certainly filed in, but in the user, the `user.project` is not filed in.

Knowing your are using a NoSQL database, you need to insert every project a user relates to in the `user.project` array. Once you have added the project ObjectID in the `user.project` array, then your related data should expose the actual project in the UI.

In your current configuration, only setting `project.user` to the value of a user will not create the correct link to display the association in your related data.

As an example:

```javascript
{
  industry: [],
  project: [ObjectId('60c9b592c99589172f73xxxx')],
  _id: 60c9b592c99589172f73fc6f,
  first_name: 'Nedra',
  last_name: 'Sauer',
  created_at: 2021-06-16T08:25:55.093Z,
  updated_at: 2021-06-16T08:25:55.093Z,
  slug: 'nedra-sauer',
  __v: 0
}

```

This would display the project with Id `60c9b592c99589172f73xxxx` in the related data of the user `Nedra Sauer`.

Can try this with a project ObjectId of your please ?

Looking forward to read you soon,

Steve.

---

<div class="post-metadata">

**Author:** ![sourabht](https://avatars.discourse-cdn.com/v4/letter/s/8491ac/32.png) [@sourabht](https://community.forestadmin.com/u/sourabht)\
**Post date:** [June 22, 2021, 4:59am UTC](https://community.forestadmin.com/t/relationship-data-not-populate-under-the-related-data/2722/13 "2021-06-22T04:59:28Z")

</div>

Thank you @anon36130554 .

We will try with project object inside the user.
