Hello, I am having some trouble with some custom relationship table.
In my models, I have a Software model, and a Feature model, the software can have many features.
I also have a featureMappingStatus model, so that the ralationship between a software and a feature has this mappingStatus as well, like so:
So I created a software-feature model that belong to the 3 other model to be able to see all the info in admin forest.
my models are defined like this
FEATURE:
// This model was generated by Lumber. However, you remain in control of your models.
// Learn how here: https://docs.forestadmin.com/documentation/v/v6/reference-guide/models/enrich-your-models
module.exports = (sequelize, DataTypes) => {
const { Sequelize } = sequelize;
// This section contains the fields of your model, mapped to your table's columns.
// Learn more here: https://docs.forestadmin.com/documentation/v/v6/reference-guide/models/enrich-your-models#declaring-a-new-field-in-a-model
const Feature = sequelize.define('feature', {
nameEn: { type: DataTypes.STRING, },
// uuid : { type: DataTypes.UUID, },
// nameFr : { type: DataTypes.STRING, },
created_at: {
type : 'TIMESTAMP',
defaultValue: 'now()',
},
updated_at: { type: DataTypes.DATE, },
}, {
hooks: {
async afterCreate(feature) {
const { software } = sequelize.models;
await feature.setSoftware(await software.findAll());
},
},
tableName : 'feature',
underscored: true,
schema : process.env.DATABASE_SCHEMA,
});
// This section contains the relationships for this model. See: https://docs.forestadmin.com/documentation/v/v6/reference-guide/relationships#adding-relationships.
Feature.associate = models => {
Feature.hasMany(models.softwareFeature, {
foreignKey: {
field: 'feature_id',
},
as: 'softwareFeature'
});
Feature.belongsToMany(models.software, {
through : 'software_feature',
foreignKey: 'feature_id',
otherKey : 'software_id',
});
Feature.belongsToMany(models.recommandation, {
through : 'recommandation_feature',
foreignKey: 'feature_id',
otherKey : 'recommandation_id',
});
Feature.belongsToMany(models.label, {
through : 'label_feature',
foreignKey: 'feature_id',
otherKey : 'label_id',
});
Feature.belongsTo(models.featureLevel, {
as: 'featureLevel'
});
};
return Feature;
};
SOFTWARE:
// This model was generated by Lumber. However, you remain in control of your models.
// Learn how here: https://docs.forestadmin.com/documentation/v/v6/reference-guide/models/enrich-your-models
module.exports = (sequelize, DataTypes) => {
const { Sequelize } = sequelize;
// This section contains the fields of your model, mapped to your table's columns.
// Learn more here: https://docs.forestadmin.com/documentation/v/v6/reference-guide/models/enrich-your-models#declaring-a-new-field-in-a-model
const Software = sequelize.define('software', {
// uuid : { type: DataTypes.UUID, },
name : { type: DataTypes.STRING, },
logo : { type: DataTypes.STRING, },
domain : { type: DataTypes.STRING, },
supportPage: { type: DataTypes.STRING, },
created_at : {
type : 'TIMESTAMP',
defaultValue: 'now()',
},
updated_at: { type: DataTypes.DATE, },
}, {
hooks: {
async afterCreate(software) {
const { feature } = sequelize.models;
await software.setFeatures(await feature.findAll());
},
},
tableName : 'software',
underscored: true,
schema : process.env.DATABASE_SCHEMA,
});
// This section contains the relationships for this model. See: https://docs.forestadmin.com/documentation/v/v6/reference-guide/relationships#adding-relationships.
Software.associate = models => {
Software.belongsTo(models.softwareType);
// Software.hasMany(models.recommandationSoftware,);
// Software.hasMany(models.internalLink);
Software.belongsToMany(models.feature, {
through : 'software_feature',
foreignKey: 'software_id',
otherKey : 'feature_id',
});
Software.hasMany(models.label);
Software.hasMany(models.softwareFeature, {
foreignKey: {
field: 'software_id',
},
as: 'softwareFeature'
});
};
return Software;
};
MAPPING STATUS
// This model was generated by Lumber. However, you remain in control of your models.
// Learn how here: https://docs.forestadmin.com/documentation/v/v6/reference-guide/models/enrich-your-models
module.exports = (sequelize, DataTypes) => {
const { Sequelize } = sequelize;
// This section contains the fields of your model, mapped to your table's columns.
// Learn more here: https://docs.forestadmin.com/documentation/v/v6/reference-guide/models/enrich-your-models#declaring-a-new-field-in-a-model
const FeatureMappingStatus = sequelize.define('featureMappingStatus', {
// uuid : { type: DataTypes.UUID, },
name : { type: DataTypes.STRING, },
created_at: {
type : 'TIMESTAMP',
defaultValue: 'now()',
},
updated_at: { type: DataTypes.DATE, },
}, {
tableName : 'feature_mapping_status',
underscored: true,
schema : process.env.DATABASE_SCHEMA,
});
// This section contains the relationships for this model. See: https://docs.forestadmin.com/documentation/v/v6/reference-guide/relationships#adding-relationships.
FeatureMappingStatus.associate = models => {
FeatureMappingStatus.hasMany(models.softwareFeature, {
foreignKey: {
name : 'featureMappingStatusIdKey',
field: 'feature_mapping_status_id',
},
});
};
return FeatureMappingStatus;
};
SOFTWARE FEATURE
// This model was generated by Lumber. However, you remain in control of your models.
// Learn how here: https://docs.forestadmin.com/documentation/v/v6/reference-guide/models/enrich-your-models
module.exports = (sequelize, DataTypes) => {
const { Sequelize } = sequelize;
// This section contains the fields of your model, mapped to your table's columns.
// Learn more here: https://docs.forestadmin.com/documentation/v/v6/reference-guide/models/enrich-your-models#declaring-a-new-field-in-a-model
const Software = sequelize.define('software', {
// uuid : { type: DataTypes.UUID, },
name : { type: DataTypes.STRING, },
logo : { type: DataTypes.STRING, },
domain : { type: DataTypes.STRING, },
supportPage: { type: DataTypes.STRING, },
created_at : {
type : 'TIMESTAMP',
defaultValue: 'now()',
},
updated_at: { type: DataTypes.DATE, },
}, {
hooks: {
async afterCreate(software) {
const { feature } = sequelize.models;
await software.setFeatures(await feature.findAll());
},
},
tableName : 'software',
underscored: true,
schema : process.env.DATABASE_SCHEMA,
});
// This section contains the relationships for this model. See: https://docs.forestadmin.com/documentation/v/v6/reference-guide/relationships#adding-relationships.
Software.associate = models => {
Software.belongsTo(models.softwareType);
// Software.hasMany(models.recommandationSoftware,);
// Software.hasMany(models.internalLink);
Software.belongsToMany(models.feature, {
through : 'software_feature',
foreignKey: 'software_id',
otherKey : 'feature_id',
});
Software.hasMany(models.label);
Software.hasMany(models.softwareFeature, {
foreignKey: {
field: 'software_id',
},
as: 'softwareFeature'
});
};
return Software;
};
Expected behavior
Be able to update a Software Feature row
Actual behavior
The Software Feature model i defined that belong to the 3 models has an id like this -> 169|62
so i can’t update it
Failure Logs
Please include any relevant log snippets, if necessary.
Context
Please provide any relevant information about your setup.
- “forest-express-sequelize”: “^6.0.0”,
- “express”: “~4.16.3”,
- “sequelize”: “~5.15.1”,
- Database Dialect: postgres
- “pg”: “~6.1.0”,
- Project Name: toolt-mvp