Relationship field on table only loads after the record is clicked

Expected behavior

The column which links to a record on another table using relationships should have the clickable values for each associated record, like in this example from the Live demo:

Actual behavior

The problem I’m having is that the value is loaded only after the record is clicked:

How my table looks when I load it:

The mcc column is a belongsTo relationship with a record on another table

After I click to open the first line:

The linked record shows as it’s supposed to, and so goes if I click the other records. But everything goes blank again if I refresh the page

Context

This is my accounts model (the table on the pictures)

module.exports = (sequelize, DataTypes) => {
  const { Sequelize } = sequelize;

  const Accounts = sequelize.define('accounts', {
    id : {type : DataTypes.UUID, primaryKey:true},
    account_id : DataTypes.STRING,
    mcc_id : DataTypes.STRING,
    name : DataTypes.STRING,
    medium : DataTypes.ENUM(['googleads','bingads']),
    platform : DataTypes.ENUM(['hotmart','eduzz','monetizze','other']),
    status : DataTypes.ENUM(['active', 'ready', 'full', 'suspended', 'canceled']),
    number : DataTypes.INTEGER
}, {
    tableName: 'accounts',
    underscored: true,
    schema: process.env.DATABASE_SCHEMA,
  });

  Accounts.associate = (models) => {
    Accounts.belongsTo(models.mccs, {foreignKey: 'mcc_id', targetKey: 'mcc_id', as: 'mcc'});
  };

  return Accounts;
};

This is my mccs model (the linked table):

module.exports = (sequelize, DataTypes) => {
  const { Sequelize } = sequelize;

  const Mccs = sequelize.define('mccs', {
    id: { type: DataTypes.UUID, primaryKey: true },
    name: DataTypes.STRING,
    mcc_id: DataTypes.STRING,
    medium: DataTypes.ENUM(['googleads', 'bingads']),
    status: DataTypes.ENUM(['active', 'ready', 'full', 'suspended', 'canceled'])
}, {
    tableName: 'mccs',
    underscored: true,
    schema: process.env.DATABASE_SCHEMA,
  });

  Mccs.associate = (models) => {
    Mccs.hasMany(models.accounts, { sourceKey: 'mcc_id', foreignKey: 'mcc_id', as: 'accounts' });
  };

  return Mccs;};

This behavior is happening in all the relationships in my database, not only in this one.

Thanks

Hi @Ian_Brant,

As I can see from your models definitions, it seems that the foreignKey on the accounts table is pointing to the mcc_id of the mccs table, not its primaryKey (id).

Is that the same for all your foreignKeys?

Hi @lamatt_v , thanks for your response

Not all of them, but I’ve just noticed that this problem happens when the foreignKey points to a not primary key

When the foreignKey points to a primary key everything seems to work fine

1 Like

@Ian_Brant thank you for reporting the issue.

It seems that ForestAdmin does not support foreignKeys pointing to non primaryKeys properly. I made a bug report card for this issue that should be prioritize soon.

1 Like