Hello there !
I’m working on forest integration in my company and we have a realy realy bad database.We have some Id as primary key but we dont use it as foreign key.
Exemple : I have some user (id, uniqueId, name,…) and some invoicing (id, price,…)
One invoicing belongsTo one linked by user.uniqueId.The probleme here is when i want to duplicate my invoicing, Forest use the primary id of user for the relation into the duplicate one.How can i change that ? I’ll try the Change a collection’s reference field of yoru documentation but it seems to only change the appareance of my linked table on the view.
This is my sequelize model :
// This model was generated by Lumber. However, you remain in control of your models.
// Learn how here: https://docs.forestadmin.com/documentation/v/v5/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/v5/reference-guide/models/enrich-your-models#declaring-a-new-field-in-a-model
const Invoicing = sequelize.define('invoicing', {
id: {
type: DataTypes.INTEGER,
field: 'Id',
primaryKey: true,
autoIncrement: true
},
userId: {
type: DataTypes.STRING,
},
requestSource: {
type: DataTypes.STRING,
},
type: {
type: DataTypes.STRING,
},
feePercentageHt: {
type: DataTypes.DOUBLE,
field: 'feePercentageHT',
},
feePercentageTtc: {
type: DataTypes.DOUBLE,
field: 'feePercentageTTC',
},
feePercentagePrepaid: {
type: DataTypes.STRING,
},
feeFlatHt: {
type: DataTypes.DOUBLE,
field: 'feeFlatHT',
},
feeFlatTtc: {
type: DataTypes.DOUBLE,
field: 'feeFlatTTC',
},
feeFlatPrepaid: {
type: DataTypes.STRING,
},
clientFeeHt: {
type: DataTypes.DOUBLE,
field: 'clientFeeHT',
},
clientFeeTtc: {
type: DataTypes.DOUBLE,
field: 'clientFeeTTC',
},
clientFeePercentHt: {
type: DataTypes.DOUBLE,
field: 'clientFeePercentHT',
},
clientFeePercentTtc: {
type: DataTypes.DOUBLE,
field: 'clientFeePercentTTC',
},
clientFeePrepaid: {
type: DataTypes.STRING,
},
debtRecovering: {
type: DataTypes.BOOLEAN,
defaultValue: Sequelize.literal('true'),
},
debtRecoveryFeeHt: {
type: DataTypes.DOUBLE,
field: 'debtRecoveryFeeHT',
},
debtRecoveryFeeTtc: {
type: DataTypes.DOUBLE,
field: 'debtRecoveryFeeTTC',
},
requestLinkId: {
type: DataTypes.STRING,
},
integration: {
type: DataTypes.STRING,
},
createdAt: {
type: DataTypes.DATE,
defaultValue: Sequelize.literal('(getdate())'),
},
}, {
tableName: 'invoicing',
timestamps: false,
});
// This section contains the relationships for this model. See: https://docs.forestadmin.com/documentation/v/v5/reference-guide/relationships#adding-relationships.
Invoicing.associate = (models) => {
Invoicing.belongsTo(models.users, {
foreignKey: 'userId',
targetKey: 'uniqueId',
keyType: DataTypes.STRING,
});
};
return Invoicing;
};
My userId and uniqueId are provided by my applicaiton, and we have some primary ID generated by MSSQL.
But all my FK refferecies are linker to another column uniqueID.
For this exemple :
user.id = mssql autoincrement
user.uniqueID = my application ID
and into my invoicing table invoicing.userId are filled with user.uniqueId.
The struggle is when i duplicate an entry with Forest, invoicing.userId are filled with user.userId generated by MSSQL. Wich is not good for me.
how can i fix that ?
thx in advance