# Smart/flattened fields with references are not resolved

**URL:** <https://community.forestadmin.com/t/smart-flattened-fields-with-references-are-not-resolved/3810>\
**Category:** Help me!\
**Created:** [December 1, 2021, 10:19am UTC](https://community.forestadmin.com/t/smart-flattened-fields-with-references-are-not-resolved/3810 "2021-12-01T10:19:49Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jganichot](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/jganichot/32/3649_2.png) [@jganichot](https://community.forestadmin.com/u/jganichot)\
**Post date:** [December 1, 2021, 10:19am UTC](https://community.forestadmin.com/t/smart-flattened-fields-with-references-are-not-resolved/3810/1 "2021-12-01T10:19:49Z")

</div>

## Feature(s) impacted

- Smart fields
- Flattened fields
- CSV export

## Observed behavior

I have a collection with smart fields and flattened fields that reference other items, in the list view, the link appears as the raw ID, and not the reference field I’ve set up in the child collection.

In the CSV export (the default of Forest), the smart field is a `JSON.stringigy`’d `ObjectID` that looks like this: `{"type": "Bufffer", "data": [12, 67, 48, 32 ...]}`. The flattened fields are represented by the `JSON.stringify`’d parent, so say I have the following document:

```javascript
{
  rootField1: 'some value'
  rootField2: '1234909908093482094' <- reference to another document
  objectField1: {
    subField1: '8983980723498249fdsff0' <- reference to other document
    subField2: '8983980723498249fdsff1' <- reference to other document
  }
}

```

With the following Mongoose model:

```javascript
{
  rootField1: String,
  rootField2: { type: Schema.Types.ObjectId, ref: 'User' },
  objectField1: {
    subField1: { type: Schema.Types.ObjectId, ref: 'Note' },
    subField2: { type: Schema.Types.ObjectId, ref: 'Product' },
  }
}

```

`rootField2` will be properly handled, so let’s say the target document is a `User` and the reference field on this collection (`Users`) is the `email`, it will appear as the `email` in the list and it will also be properly serialized in the CSV.

But in my table I will see the column `objectField1 -> subfield1` as `8983980723498249fdsff0`.

In my export, the `objectField1 -> subfield1` value will be `"{"subfFeld1": "8983980723498249fdsff0", "subField2": "8983980723498249fdsff1"}"` where I’m expecting a string with the referenced field value within the target collection.

The same behavior occurs for a smart field, I will see the raw ID in the list, and a `JSON.stringify`’d ObjectID in the CSV export

List view:

 ![Screenshot 2021-12-01 at 10.38.01](https://europe1.discourse-cdn.com/flex013/uploads/forest/original/2X/e/e0429d8c03fe148cfc30317db69181c4a7b50d01.png)  
Here the flatten fields are Raw IDs but the `created by` field was properly referenced.

CSV:

 ![Screenshot 2021-12-01 at 10.39.06](https://europe1.discourse-cdn.com/flex013/uploads/forest/original/2X/1/1a6fad93efa593b9010f415635abd4f860697661.png)  
Broken because the JSON has separators

**Sorry for the lack of images but it seems to be broken, I get an error telling me to try again later.**  
**The image upload does not work on Firefox FYI**

## Expected behavior

What I’m expecting is to see the referenced document’s reference field value and not the raw ID in the table or any`JSON.stringify`’d object in my CSV export.

This is a critical feature I need to use, we are paying a quite expensive plan and in the end I always have to reimplement all the routes to simply display/export things properly. But obviously I’m loosing all the filtering features and other things that actually make Forest admin actually valuable…

## Context

Current version of `forest-express-mongoose` is `8.4.4`  
Current version of `mongoose` is `5.13.13`  
The problem occurs on all my environments.

---

<div class="post-metadata">

**Author:** ![anon23361380](https://avatars.discourse-cdn.com/v4/letter/a/67e7ee/32.png) [@anon23361380](https://community.forestadmin.com/u/anon23361380)\
**Post date:** [December 1, 2021, 11:29am UTC](https://community.forestadmin.com/t/smart-flattened-fields-with-references-are-not-resolved/3810/2 "2021-12-01T11:29:29Z")

</div>

Hello @jganichot ,

Sorry to hear that! I am trying to reproduce your error and will get to you as soon as possible

---

<div class="post-metadata">

**Author:** ![jganichot](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/jganichot/32/3649_2.png) [@jganichot](https://community.forestadmin.com/u/jganichot)\
**Post date:** [December 1, 2021, 12:12pm UTC](https://community.forestadmin.com/t/smart-flattened-fields-with-references-are-not-resolved/3810/3 "2021-12-01T12:12:58Z")

</div>

Hi @anon23361380

Thanks! I updated my original post with images, the upload is just not working on Firefox.
