# SmartCollection not displaying fields

**URL:** https://community.forestadmin.com/t/smartcollection-not-displaying-fields/5867
**Category:** Help me!
**Tags:** smart-collection
**Created:** [January 18, 2023, 11:22am UTC](https://community.forestadmin.com/t/smartcollection-not-displaying-fields/5867 "2023-01-18T11:22:46Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Lionel](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/lionel/32/5105_2.png) [@Lionel](https://community.forestadmin.com/u/Lionel)
#### Post date: [January 18, 2023, 11:22am UTC](https://community.forestadmin.com/t/smartcollection-not-displaying-fields/5867/1 "2023-01-18T11:22:46Z")

</div>

## Feature(s) impacted

SmartCollection

## Observed behavior

The route to my Smartcollection works fine but is displaying an empty list with no fields. The “Fields” tab is neither clickable when trying to edit the layout.

 ![Capture d’écran du 2023-01-18 13-15-04](https://europe1.discourse-cdn.com/flex013/uploads/forest/original/2X/c/c6da22957ad9008d9f0cf5d9e66e454f2a527296.png)

## Expected behavior

SmartCollections displaying the expected fields.

## Failure Logs

No failure logs, I’ve probably missed something else…

console log of data sent by “get” route :

> {  
> type: ‘pDComment’,  
> id: ‘110755c2-247d-447a-90da-92471d382f09’,  
> attributes: {  
> id: ‘110755c2-247d-447a-90da-92471d382f09’,  
> description: `"Gouverner c'est prévoir". Apparemment, nous n'avons plus de gouvernants depuis quelques décennies...`,  
> published\_at: 2022-07-24T09:50:00.000Z  
> }  
> }  
> …

## Context

- Project name: PolitizrForest

- Team name: Operations

- Environment name: Development

- Agent type & version:  
“body-parser”: “1.19.0”,  
“chalk”: “~1.1.3”,  
“cookie-parser”: “1.4.4”,  
“cors”: “2.8.5”,  
“debug”: “~4.0.1”,  
“dotenv”: “~6.1.0”,  
“express”: “~4.17.1”,  
“express-jwt”: “6.1.2”,  
“forest-cli”: “^3.0.6”,  
“forest-express-sequelize”: “^8.0.0”,  
“morgan”: “1.9.1”,  
“mysql2”: “~2.2.5”,  
“require-all”: “^3.0.0”,  
“sequelize”: “~5.15.1”

- Recent changes made on your end if any:

I’m trying to get a single view (SQL’s “Union”) of 2 tables (p\_d\_d\_comment + p\_d\_r\_comment =\> p\_d\_comment).

I read the [documentation](https://docs.forestadmin.com/documentation/reference-guide/smart-collections) to help me, but I’m not familiar with JS coding.

**forest/p-d-comment.js** :

```javascript
const { collection } = require('forest-express-sequelize');
const models = require('../models');

// Union of pddcomment & pdrcomment collection
collection('pDComment', {
    isSearchable: true,
    fields: [{
        field: 'id',
        type: String,
    }, {
        field: 'description',
        type: String,
    }, {
        field: 'published_at',
        type: Date,
    }],
});

```

**routes/p-d-comment.js** :

```javascript
// Grouping of pddcomment & pdrcomment collection
const { RecordSerializer } = require('forest-express-sequelize');
const express = require('express');
const router = express.Router();
const { connections } = require('../models');

const sequelize = connections.default;

router.get('/pDComment', (req, res, next) => {
  const limit = parseInt(req.query.page.size) || 20;
  const offset = (parseInt(req.query.page.number) - 1) * limit;
  const queryType = sequelize.QueryTypes.SELECT;

  const queryData = `
    SELECT d.uuid as id, d.description as description, d.published_at as published_at
    FROM p_d_d_comment as d
    
    UNION
    
    SELECT r.uuid as id, r.description as description, r.published_at as published_at
    FROM p_d_r_comment as r
    
    ORDER BY published_at desc
    LIMIT ${limit}
    OFFSET ${offset}
  `;

  const queryCount = `
    SELECT sum(tbl.tblCount) as count
    FROM
        (
        SELECT count(*) as tblCount from p_d_d_comment
        UNION ALL
        SELECT count(*) as tblCount from p_d_r_comment
        ) tbl;
  `;

  Promise.all([
    sequelize.query(queryData, { type: queryType }),
    sequelize.query(queryCount, { type: queryType }),
  ])
    .then(async ([pDCommentsList, pDCommentsCount]) => {
      const pDCommentSerializer = new RecordSerializer({ name: 'pDComment' });
      const pDComments = await pDCommentSerializer.serialize(pDCommentsList);
      const count = pDCommentsCount[0].count;
      res.send({ ...pDComments, meta:{ count: count }});
    })
    .catch((err) => next(err));
});

module.exports = router;

```

---

<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: [January 18, 2023, 2:03pm UTC](https://community.forestadmin.com/t/smartcollection-not-displaying-fields/5867/4 "2023-01-18T14:03:01Z")

</div>

Hi @Lionel 👋 and welcome to our community.  
I think there is an error on your console of your browser can you share it with us please.

---

<div class="post-metadata">

### Author: ![Lionel](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/lionel/32/5105_2.png) [@Lionel](https://community.forestadmin.com/u/Lionel)
#### Post date: [January 18, 2023, 5:47pm UTC](https://community.forestadmin.com/t/smartcollection-not-displaying-fields/5867/5 "2023-01-18T17:47:22Z")

</div>

Thanks @Arnaud_Moncel 👍

Yes, you’re right, I forget to check the console, here is the error

> companion-bubble.js:1465 Uncaught (in promise) TypeError: Cannot convert undefined or null to object  
> at Function.keys ()  
> at companion-bubble.js:1465:19726  
> at Generator.next ()  
> at Ln (companion-bubble.js:1465:19144)  
> chunk.675.c87c323478477298af28.js:2 Forest Admin 🌲 Start third-party services tracking.

---

<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: [January 19, 2023, 8:35am UTC](https://community.forestadmin.com/t/smartcollection-not-displaying-fields/5867/6 "2023-01-19T08:35:14Z")

</div>

It seems not to be related to the issue.  
I’m asking something, the field type should be under quotes.

```javascript
{
  field: 'id',
  type: String,
}

```

should be

```javascript
{
  field: 'id',
  type: 'String',
}

```

Can you try this? 🙏

---

<div class="post-metadata">

### Author: ![Lionel](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/lionel/32/5105_2.png) [@Lionel](https://community.forestadmin.com/u/Lionel)
#### Post date: [January 19, 2023, 8:56am UTC](https://community.forestadmin.com/t/smartcollection-not-displaying-fields/5867/7 "2023-01-19T08:56:33Z")

</div>

Thanks @Arnaud_Moncel , you’ve got it, it works, sorry for my mistakes. 🫣
