# Reference key display issue

**URL:** <https://community.forestadmin.com/t/reference-key-display-issue/1568>\
**Category:** Help me!\
**Created:** [January 4, 2021, 5:28pm UTC](https://community.forestadmin.com/t/reference-key-display-issue/1568 "2021-01-04T17:28:15Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![JeremyV](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/jeremyv/32/1033_2.png) [@JeremyV](https://community.forestadmin.com/u/JeremyV)\
**Post date:** [January 4, 2021, 5:28pm UTC](https://community.forestadmin.com/t/reference-key-display-issue/1568/1 "2021-01-04T17:28:15Z")

</div>

I created a smart field and defined it as a reference field

 ![Screenshot 2021-01-04 181628](https://europe1.discourse-cdn.com/flex013/uploads/forest/original/2X/f/fdc8effaa01276af2233ba585373fe246d845454.png)

I create a new record in another collection, linking it with one of the key records (loaded with hooks/load)  
 ![Screenshot 2021-01-04 181745](https://europe1.discourse-cdn.com/flex013/uploads/forest/original/2X/b/b5924b8adf4b351f120e164f794196d9a2141223.png)

If i go in the summary view of the newly created record, everything looks fine  
 ![Screenshot 2021-01-04 181817](https://europe1.discourse-cdn.com/flex013/uploads/forest/original/2X/0/024ef6cc5be966c7cef6371bcde142eda9e1c46a.png)

BUT, if i display the records WITHIN its parent (related data)

 ![Screenshot 2021-01-04 182005](https://europe1.discourse-cdn.com/flex013/uploads/forest/original/2X/6/6d9c5d79f45940f9be84bd6689ae87585e13ffa6.png)

It the records collection, everything is displayed normally

 ![Screenshot 2021-01-04 182638](https://europe1.discourse-cdn.com/flex013/uploads/forest/original/2X/5/5415b8689cde9f273d4aa29ff5f08ebd239301ef.png)

The “get” method for the smart reference field is not even asynchronous:

`get: repartitionKey => ${repartitionKey.letter} - ${repartitionKey.displayName} - ${repartitionKey.feesTotal} `

(removed some code for example purpose)

## Expected behavior

Reference key fields displayed as in the collection

## Actual behavior

Some data are not retrieved.

---

<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 5, 2021, 9:32am UTC](https://community.forestadmin.com/t/reference-key-display-issue/1568/2 "2021-01-05T09:32:55Z")

</div>

Hi @JeremyV 👋 thank you to your feedback.  
Can you give me more information about the `repartionKey` model,  
and the entire code of the `get` method please.

---

<div class="post-metadata">

**Author:** ![JeremyV](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/jeremyv/32/1033_2.png) [@JeremyV](https://community.forestadmin.com/u/JeremyV)\
**Post date:** [January 5, 2021, 10:02am UTC](https://community.forestadmin.com/t/reference-key-display-issue/1568/3 "2021-01-05T10:02:06Z")

</div>

_repartitionKey_ Model:

```javascript
const RepartitionKeys = sequelize.define('repartitionKeys', {
    letter: { type: DataTypes.STRING, },
    displayName: { type: DataTypes.STRING, },
    feesTotal: { type: DataTypes.INTEGER, },
    createdAt: { type: DataTypes.DATE, },
    updatedAt: { type: DataTypes.DATE, },
    sergicId: { type: DataTypes.STRING, },
  }, {
    tableName: 'repartition_keys',
    underscored: true,
    schema: process.env.DATABASE_SCHEMA,
  });

```

get method:

```javascript
get: repartitionKey => repartitionKey && repartitionKey.letter && repartitionKey.displayName && repartitionKey.feesTotal ? `${repartitionKey.letter} - ${repartitionKey.displayName} - ${repartitionKey.feesTotal}` : `${repartitionKey.letter} - ${repartitionKey.displayName}` 

```

---

<div class="post-metadata">

**Author:** ![Louis-Marie](https://avatars.discourse-cdn.com/v4/letter/l/258eb7/32.png) [@Louis-Marie](https://community.forestadmin.com/u/Louis-Marie)\
**Post date:** [January 5, 2021, 10:46am UTC](https://community.forestadmin.com/t/reference-key-display-issue/1568/4 "2021-01-05T10:46:44Z")

</div>

Hi,

Just in case, are you sure that you are using the last releases?  
I raised the same issue recently, and it was solved in the last release.

Best

---

<div class="post-metadata">

**Author:** ![JeremyV](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/jeremyv/32/1033_2.png) [@JeremyV](https://community.forestadmin.com/u/JeremyV)\
**Post date:** [January 5, 2021, 12:20pm UTC](https://community.forestadmin.com/t/reference-key-display-issue/1568/5 "2021-01-05T12:20:42Z")

</div>

> [@Louis-Marie](#):
>
> I raised the same issue recently, and it was solved in the last release.

Which package should I upgrade ? I upgraded forest-express and forest-express-sequelize quite recently.

---

<div class="post-metadata">

**Author:** ![Louis-Marie](https://avatars.discourse-cdn.com/v4/letter/l/258eb7/32.png) [@Louis-Marie](https://community.forestadmin.com/u/Louis-Marie)\
**Post date:** [January 5, 2021, 1:10pm UTC](https://community.forestadmin.com/t/reference-key-display-issue/1568/6 "2021-01-05T13:10:56Z")

</div>

I had to update to the latest ones:

- forest-express-sequelize 6.6.3
- forest-express 7.9.4

The versions of forest-express-sequelize from 6.6.1 to 6.6.2 have problems with smart fields.

---

<div class="post-metadata">

**Author:** ![JeremyV](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/jeremyv/32/1033_2.png) [@JeremyV](https://community.forestadmin.com/u/JeremyV)\
**Post date:** [January 5, 2021, 2:03pm UTC](https://community.forestadmin.com/t/reference-key-display-issue/1568/7 "2021-01-05T14:03:23Z")

</div>

we have the same versions.

```javascript
"forest-express": "^7.9.4",
"forest-express-sequelize": "^6.6.3"

```

The smart fields used as reference keys do display correctly, except in the specific context of related data.

---

<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 5, 2021, 3:14pm UTC](https://community.forestadmin.com/t/reference-key-display-issue/1568/8 "2021-01-05T15:14:58Z")

</div>

I’m not able to reproduce … I think I’m missing information.  
Maybe a small video record of your workflow should be help.

---

<div class="post-metadata">

**Author:** ![JeremyV](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/jeremyv/32/1033_2.png) [@JeremyV](https://community.forestadmin.com/u/JeremyV)\
**Post date:** [January 6, 2021, 11:55am UTC](https://community.forestadmin.com/t/reference-key-display-issue/1568/10 "2021-01-06T11:55:18Z")

</div>

I think i got it : the object attributes’names are truncated to 6 characters.

```javascript
dataValues: {
    id: '24',
    letter: 'A',
    displa: 'Chauffage central',
    feesTo: 2000,
    ...
  }

```

but i call

```javascript
repartitionKey.letter
repartitionKey.displayName
repartitionKey.feesTotal

```

---

<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:** [January 6, 2021, 12:18pm UTC](https://community.forestadmin.com/t/reference-key-display-issue/1568/11 "2021-01-06T12:18:21Z")

</div>

Hello @JeremyV,

Indeed this is a bit weird. Do you have an idea why the keys are truncated to 6 characters?

Did you try with `displa` and `feesTo`?

Let me know 🙂

---

<div class="post-metadata">

**Author:** ![JeremyV](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/jeremyv/32/1033_2.png) [@JeremyV](https://community.forestadmin.com/u/JeremyV)\
**Post date:** [January 6, 2021, 12:41pm UTC](https://community.forestadmin.com/t/reference-key-display-issue/1568/12 "2021-01-06T12:41:03Z")

</div>

Surprisingly it doesn’t work when i call `displa` and `feesTo`.

But by doing this, the display in the collection and the summary view (which require displayName and FeesTotal) won’t work anymore.

In a nutshell :

- when the route  
`/forest/integrationBudgets/12/relationships/integrationBudgetIntegrationBudgetEntries` is called, the attributes are truncated.
- when the route `/forest/integrationBudgetEntries/22` is called, the attributes aren’t truncated and displayed as normal
- when the route `/forest/integrationBudgetEntries` is called, everything is displayed normally

---

<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:** [January 6, 2021, 1:03pm UTC](https://community.forestadmin.com/t/reference-key-display-issue/1568/13 "2021-01-06T13:03:08Z")

</div>

Indeed, this is surprising.

Could you share with us your models declaration, especially the one for `integrationBudgetIntegrationBudgetEntries`?

Also the `app.js` would be very helpful in order to see your middlewares. Maybe we could understand why the keys are truncated to 6 characters.

Can we also see the code of your hooks/load?

Did you customize anything?

Thank you,

---

<div class="post-metadata">

**Author:** ![JeremyV](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/jeremyv/32/1033_2.png) [@JeremyV](https://community.forestadmin.com/u/JeremyV)\
**Post date:** [January 6, 2021, 1:22pm UTC](https://community.forestadmin.com/t/reference-key-display-issue/1568/14 "2021-01-06T13:22:49Z")

</div>

```javascript
const IntegrationBudgets = sequelize.define('integrationBudgets', {
    partnerComment: { type: DataTypes.STRING, },
    refusalComment: { type: DataTypes.STRING, },
    state: { type: DataTypes.ENUM(['initializing', 'waiting', 'accepted', 'refused']),},
    createdAt: { type: DataTypes.DATE, },
    updatedAt: { type: DataTypes.DATE, },
  }, {
    tableName: 'integration_budgets',
    underscored: true,
    schema: process.env.DATABASE_SCHEMA,
  });

  IntegrationBudgets.associate = (models) => {
    IntegrationBudgets.belongsTo(models.places, {
      foreignKey: {
        name: 'placeIdKey',
        field: 'place_id',
      },
      as: 'place',
    });
    IntegrationBudgets.belongsTo(models.integrations, {
      foreignKey: {
        name: 'placeIdKey',
        field: 'place_id',
      },
      as: 'integration',
    });
    IntegrationBudgets.hasMany(models.integrationBudgetEntries, {
      foreignKey: {
        name: 'integrationBudgetIdKey',
        field: 'integration_budget_id',
      },
      as: 'integrationBudgetIntegrationBudgetEntries',
    });
  };

```

```javascript
  const IntegrationBudgetEntries = sequelize.define('integrationBudgetEntries', {
    displayName: { type: DataTypes.STRING, },
    amount: { type: DataTypes.INTEGER, },
    createdAt: { type: DataTypes.DATE, },
    updatedAt: { type: DataTypes.DATE, },
  }, {
    tableName: 'integration_budget_entries',
    underscored: true,
    schema: process.env.DATABASE_SCHEMA,
  });

  IntegrationBudgetEntries.associate = (models) => {
    IntegrationBudgetEntries.belongsTo(models.repartitionKeys, {
      foreignKey: {
        name: 'repartitionKeyIdKey',
        field: 'repartition_key_id',
      },
      as: 'repartitionKey',
    });
    IntegrationBudgetEntries.belongsTo(models.integrationBudgets, {
      foreignKey: {
        name: 'integrationBudgetIdKey',
        field: 'integration_budget_id',
      },
      as: 'integrationBudget',
    });
  };
  return IntegrationBudgetEntries;
};

```

The /forest/integration-budget-entries.js file is untouched.  
The /forest/integration-budgets.js is as following, 2 smart actions :

```javascript
collection('integrationBudgets', {
  actions: [{
    name: 'Demander validation budget',
    type: 'single',
  }, {
    name: 'Ajouter ligne budget',
    type: 'single',
    fields: [{
      field: 'Clef de repartition',
      type: 'Enum',
      enums: []
    }, {
      field: 'Libelle',
      type: 'String',
    }, {
      field: 'Montant',
      type: 'Number'
    }],
    hooks: {
      load: ({ fields, record }) => models.repartitionKeys.findAll({
        where: { place_id: record.place.id }
      }).then(repartitionKeys => {
        fields['Clef de repartition'].enums = repartitionKeys.map(repartitionKey => `${repartitionKey.letter} - ${repartitionKey.displayName} - ${repartitionKey.feesTotal}`);
        return fields;
      })
    }
  }],
  fields: [],
  segments: [],
});

```

---

<div class="post-metadata">

**Author:** ![JeremyV](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/jeremyv/32/1033_2.png) [@JeremyV](https://community.forestadmin.com/u/JeremyV)\
**Post date:** [January 6, 2021, 1:28pm UTC](https://community.forestadmin.com/t/reference-key-display-issue/1568/15 "2021-01-06T13:28:24Z")

</div>

In order to associate the budget entry to the repartition key, i retrieve in the smart action route the repartitionKeyId, as follows :

```javascript
router.post('/actions/ajouter-ligne-budget', permissionMiddlewareCreator.smartAction(), (request, response) => {
  const recordCreator = new RecordCreator(models.integrationBudgetEntries);
  const data = request.body.data.attributes.values;
  const repartitionKeyAttributes = data['Clef de repartition'].split(' - ');

  models.repartitionKeys.findOne({
    where: {
      letter: repartitionKeyAttributes[0],
      display_name: repartitionKeyAttributes[1],
      fees_total: repartitionKeyAttributes[2]
    }
  }).then(repartitionKey => {
    const integration_budget_id = request.body.data.attributes.ids[0];

    const body = {
      integration_budget_entry: {
        integration_budget_id,
        display_name: data.Libelle,
        repartition_key_id: repartitionKey.id,
        amount: data.Montant
      }
    };

    axios.post(`${API_URL}/oauth/token`, {
      'scope': process.env.SCOPE,
      'client_id': process.env.CLIENT_ID,
      'client_secret': process.env.CLIENT_SECRET,
      'grant_type': process.env.GRANT_TYPE
    }).then(authenticationResponse => {
      const accessToken = authenticationResponse.data.access_token;
      axios.post(`${API_URL}/forest_admin/integration_budget_entries`, body, {
        headers: {
          'Authorization': `Bearer ${accessToken}`,
          'X-CURRENT-USER-EMAIL': request.user.email
        },
      }).then(async res => {
        response.send(await recordCreator.serialize(res.data));
      }).catch(err => {
        response.status(400).send(err.response.data.error.message);
      });
    }).catch(authenticationError => {
      response.status(authenticationError.response.status).send(authenticationError.message);
    });
  });
});

```

… but it has nothing to do with the data display in itself.

---

<div class="post-metadata">

**Author:** ![JeremyV](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/jeremyv/32/1033_2.png) [@JeremyV](https://community.forestadmin.com/u/JeremyV)\
**Post date:** [January 6, 2021, 1:30pm UTC](https://community.forestadmin.com/t/reference-key-display-issue/1568/16 "2021-01-06T13:30:20Z")

</div>

I didn’t customize any of the previously mentioned GET routes.

I have full GET access (directly via sequelize), I need to call APIs for any POST/PUT/DELETE call.

---

<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:** [January 6, 2021, 2:01pm UTC](https://community.forestadmin.com/t/reference-key-display-issue/1568/17 "2021-01-06T14:01:49Z")

</div>

Thank you @JeremyV,

Could you also share your model for `repartitionKeys` please?  
I think it will help us more 🙂

---

<div class="post-metadata">

**Author:** ![JeremyV](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/jeremyv/32/1033_2.png) [@JeremyV](https://community.forestadmin.com/u/JeremyV)\
**Post date:** [January 6, 2021, 3:05pm UTC](https://community.forestadmin.com/t/reference-key-display-issue/1568/18 "2021-01-06T15:05:44Z")

</div>

@Guillaume_Cisco you already have it above.

> [@JeremyV](#):
>
> ```javascript
> const RepartitionKeys = sequelize.define('repartitionKeys', {
> letter: { type: DataTypes.STRING, },
> displayName: { type: DataTypes.STRING, },
> feesTotal: { type: DataTypes.INTEGER, },
> createdAt: { type: DataTypes.DATE, },
> updatedAt: { type: DataTypes.DATE, },
> sergicId: { type: DataTypes.STRING, },
> }, {
> tableName: 'repartition_keys',
> underscored: true,
> schema: process.env.DATABASE_SCHEMA,
> });
> 
> ```

Relations are :

```javascript
RepartitionKeys.associate = (models) => {

    RepartitionKeys.belongsTo(models.places, {
      foreignKey: {
        name: 'placeIdKey',
        field: 'place_id',
      },
      as: 'place',
    });

    RepartitionKeys.belongsTo(models.integrations, {
      foreignKey: {
        name: 'placeIdKey',
        field: 'place_id',
      },
      as: 'integration',
    });

    RepartitionKeys.hasMany(models.accountPlaceEntries, {
      foreignKey: {
        name: 'repartitionKeyIdKey',
        field: 'repartition_key_id',
      },
      as: 'repartitionKeyAccountPlaceEntries',
    });

    RepartitionKeys.hasMany(models.generalMeetings, {
      foreignKey: {
        name: 'repartitionKeyIdKey',
        field: 'repartition_key_id',
      },
      as: 'repartitionKeyGeneralMeetings',
    });

    RepartitionKeys.hasMany(models.parcelRepartitionKeys, {
      foreignKey: {
        name: 'repartitionKeyIdKey',
        field: 'repartition_key_id',
      },
      as: 'repartitionKeyParcelRepartitionKeys',
    });

    RepartitionKeys.hasMany(models.resolutions, {
      foreignKey: {
        name: 'repartitionKeyIdKey',
        field: 'repartition_key_id',
      },
      as: 'repartitionKeyResolutions',
    });

    RepartitionKeys.hasMany(models.buildingRepartitionKeys, {
      foreignKey: {
        name: 'repartitionKeyIdKey',
        field: 'repartition_key_id',
      },
      as: 'repartitionKeyBuildingRepartitionKeys',
    });

    RepartitionKeys.hasMany(models.identityRepartitionKeys, {
      foreignKey: {
        name: 'repartitionKeyIdKey',
        field: 'repartition_key_id',
      },
      as: 'repartitionKeyIdentityRepartitionKeys',
    });

    RepartitionKeys.hasMany(models.contractRepartitionKeys, {
      foreignKey: {
        name: 'repartitionKeyIdKey',
        field: 'repartition_key_id',
      },
      as: 'repartitionKeyContractRepartitionKeys',
    });

    RepartitionKeys.hasMany(models.decisions, {
      foreignKey: {
        name: 'repartitionKeyIdKey',
        field: 'repartition_key_id',
      },
      as: 'repartitionKeyDecisions',
    });
  };
  return RepartitionKeys;
};

```

---

<div class="post-metadata">

**Author:** ![JeremyV](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/jeremyv/32/1033_2.png) [@JeremyV](https://community.forestadmin.com/u/JeremyV)\
**Post date:** [January 7, 2021, 7:59am UTC](https://community.forestadmin.com/t/reference-key-display-issue/1568/19 "2021-01-07T07:59:22Z")

</div>

> [@Guillaume\_Cisco](#):
>
> `app.js` would be very helpful in order to see your middlewares,

Sorry, forgot to include it.

```javascript
const express = require('express');
const requireAll = require('require-all');
const path = require('path');
const cookieParser = require('cookie-parser');
const bodyParser = require('body-parser');
const cors = require('cors');
const jwt = require('express-jwt');
const morgan = require('morgan');
const { errorHandler, logger } = require('forest-express');
const {
  ensureAuthenticated,
  PUBLIC_ROUTES,
} = require('forest-express-sequelize');

const app = express();

app.use(morgan('tiny'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));

let allowedOrigins = [/\.forestadmin\.com$/];

if (process.env.CORS_ORIGINS) {
  allowedOrigins = allowedOrigins.concat(process.env.CORS_ORIGINS.split(','));
}

app.use(cors({
  origin: allowedOrigins,
  allowedHeaders: ['Authorization', 'X-Requested-With', 'Content-Type'],
  maxAge: 86400, // NOTICE: 1 day
  credentials: true,
}));

app.use(jwt({
  secret: process.env.FOREST_AUTH_SECRET,
  credentialsRequired: false,
}));

app.use('/forest', (request, response, next) => {
  if (PUBLIC_ROUTES.includes(request.url)) {
    return next();
  }
  return ensureAuthenticated(request, response, next);
});

requireAll({
  dirname: path.join(__dirname, 'routes'),
  recursive: true,
  resolve: (Module) => app.use('/forest', Module),
});

requireAll({
  dirname: path.join(__dirname, 'middlewares'),
  recursive: true,
  resolve: (Module) => Module(app),
});

app.use(errorHandler({ logger }));

module.exports = app;

```

---

<div class="post-metadata">

**Author:** ![JeremyV](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/jeremyv/32/1033_2.png) [@JeremyV](https://community.forestadmin.com/u/JeremyV)\
**Post date:** [January 7, 2021, 8:01am UTC](https://community.forestadmin.com/t/reference-key-display-issue/1568/20 "2021-01-07T08:01:34Z")

</div>

@Guillaume_Cisco do you need the content of the `/middlewares` folder ?

---

<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:** [January 7, 2021, 10:27am UTC](https://community.forestadmin.com/t/reference-key-display-issue/1568/21 "2021-01-07T10:27:21Z")

</div>

Hello @JeremyV 👋

I’m taking care of the issue from now one. I have every information I need to investigate. I’m currently trying to reproduce.

I will keep you in touch as soon as I have something 🙂

Steve

[Next page](https://community.forestadmin.com/t/reference-key-display-issue/1568.md?page=2)
