I’m newish to Adminjs and I’m having the following challenge:
I have one table with both id
and name
columns. Adminjs automatically shows the name
value for columns that are referenced with a foreign key to the id
of the parent table. (Great feature!)
I have another foreign key relationship to a parent table that has a column labeled proper_name
instead of just name
. I would love to recreate this table display behavior with the proper_name
column values being displayed instead of just displaying the parent table foreign key id
values when referencing the foreign key related table.
Is there a way to customize/override this display behavior so the dropdown shows the value of another column from the parent table other than the id
column?
parent table model:
class parent_1_table extends Model {
static associate(models) {
}
}
parent_table.init({
id: {
type: Sequelize.BIGINT,
primaryKey: true,
autoIncrement: true,
},
proper_name: {
type: Sequelize.STRING(32),
isTitle: true,
},
}, {
sequelize,
modelName: 'parent_table',
timestamps: false,
createdAt: false,
updatedAt: false,
freezeTableName: true,
tableName: 'parent_table',
});
child table:
class child_table extends Model {
static associate(models) {
}
}
child_table.init({
parent_1_id: {
type: Sequelize.BIGINT,
allowNull: false,
},
parent_2_id: {
type: Sequelize.BIGINT,
allowNull: false,
},
}, {
sequelize,
modelName: 'child_table',
timestamps: false,
createdAt: false,
updatedAt: false,
freezeTableName: true,
tableName: 'child_table',
});
foreign key relationships are defined after the fact in the index.js
file:
child_table.belongsTo(parent_1_table, { foreignKey: 'parent_1_id' });
child_table.belongsTo(parent_2, { foreignKey: 'parent_2_id' });