我对行政管理很陌生,我面临着以下挑战:我有一个同时包含id和name列的表。Adminjs自动显示用外键引用到父表的name的列的id值。(很棒的特征!)
我与一个父表有另一个外键关系,该表有一个标记为proper_name的列,而不仅仅是name。我希望通过显示proper_name列值重新创建此表显示行为,而不是在引用外键相关表时仅显示父表外键id值。
是否有一种自定义/重写此显示行为的方法,以便下拉列表显示父表中除id列之外的另一列的值?
父表模型:
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',
});儿童桌:
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',
});外键关系是在index.js文件的事实之后定义的:
child_table.belongsTo(parent_1_table, { foreignKey: 'parent_1_id' });
child_table.belongsTo(parent_2, { foreignKey: 'parent_2_id' });发布于 2022-06-27 07:37:25
社区中的项目贡献者之一澄清了上述isTitle: true解决方案需要在选项领域的列定义之后:
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, * not here
},
}, {
sequelize,
properties: { // put these display options here!
proper_name: {
isTitle: true,
},
},
modelName: 'parent_table',
timestamps: false,
createdAt: false,
updatedAt: false,
freezeTableName: true,
tableName: 'parent_table',
});https://stackoverflow.com/questions/72765502
复制相似问题