Hello,
I have an issue with my project sponsoplus-admin
. I can’t load elements with auto-completion from ‘user’ relation to create a new cashbackTransaction
entity. Strangely, it’s working for the ‘club’ relation.
I’m working with forest-express-sequelize 7.0.0
and sequelize ~5.15.1
.
Here is my t-e-cashback-transaction.js
model where I want to create the element:
// This model was generated by Forest CLI. 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 TECashbackTransaction = sequelize.define('tECashbackTransaction', {
createdAt: {
type: DataTypes.DATE,
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP'),
},
updatedAt: {
type: DataTypes.DATE,
defaultValue: Sequelize.literal('now()'),
},
deletedAt: {
type: DataTypes.DATE,
},
id: {
type: DataTypes.UUID,
primaryKey: true,
defaultValue: Sequelize.literal('uuid_generate_v4()'),
allowNull: false,
},
transactionId: {
type: DataTypes.STRING,
allowNull: false,
},
amount: {
type: DataTypes.DOUBLE,
allowNull: false,
},
currency: {
type: DataTypes.STRING,
allowNull: false,
},
userCashbackAmount: {
type: DataTypes.DOUBLE,
allowNull: false,
},
clubCashbackAmount: {
type: DataTypes.DOUBLE,
allowNull: false,
},
transactionDate: {
type: DataTypes.DATE,
allowNull: false,
},
label: {
type: DataTypes.STRING,
allowNull: false,
},
origin: {
type: DataTypes.ENUM(
'Azela',
),
allowNull: false,
},
metadata: {
type: DataTypes.JSONB,
allowNull: false,
},
status: {
type: DataTypes.ENUM(
'YES',
'NO',
'PENDING',
),
allowNull: false,
},
}, {
tableName: 't_e_cashback_transaction',
underscored: true,
});
// This section contains the relationships for this model. See: https://docs.forestadmin.com/documentation/v/v6/reference-guide/relationships#adding-relationships.
TECashbackTransaction.associate = (models) => {
TECashbackTransaction.belongsTo(models.tEUserWithdraw, {
foreignKey: {
name: 'userWithdrawIdKey',
field: 'user_withdraw_id',
},
as: 'userWithdraw',
});
TECashbackTransaction.belongsTo(models.tEClubWithdraw, {
foreignKey: {
name: 'clubWithdrawIdKey',
field: 'club_withdraw_id',
},
as: 'clubWithdraw',
});
TECashbackTransaction.belongsTo(models.tEUser, {
foreignKey: {
name: 'userIdKey',
field: 'user_id',
},
as: 'user',
});
TECashbackTransaction.belongsTo(models.tEClub, {
foreignKey: {
name: 'clubIdKey',
field: 'club_id',
},
as: 'club',
});
};
return TECashbackTransaction;
};
Here is my t-e-club.js
model:
// This model was generated by Forest CLI. 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 TEClub = sequelize.define('tEClub', {
id: {
type: DataTypes.UUID,
primaryKey: true,
defaultValue: Sequelize.literal('uuid_generate_v4()'),
allowNull: false,
},
name: {
type: DataTypes.STRING,
allowNull: false,
},
beSportId: {
type: DataTypes.STRING,
},
logoUrl: {
type: DataTypes.STRING,
},
sportId: {
type: DataTypes.INTEGER,
},
clubUrl: {
type: DataTypes.STRING,
},
}, {
tableName: 't_e_club',
underscored: true,
timestamps: false,
});
// This section contains the relationships for this model. See: https://docs.forestadmin.com/documentation/v/v6/reference-guide/relationships#adding-relationships.
TEClub.associate = (models) => {
TEClub.hasMany(models.tEUser, {
foreignKey: {
name: 'selectedClubIdKey',
field: 'selected_club_id',
},
as: 'selectedClubTEUsers',
});
TEClub.hasMany(models.tECashbackTransaction, {
foreignKey: {
name: 'clubIdKey',
field: 'club_id',
},
as: 'clubTECashbackTransactions',
});
TEClub.hasMany(models.tEClubWithdraw, {
foreignKey: {
name: 'clubIdKey',
field: 'club_id',
},
as: 'clubTEClubWithdraws',
});
};
return TEClub;
};
And here is my t-e-user.js
model:
// This model was generated by Forest CLI. 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 TEUser = sequelize.define('tEUser', {
createdAt: {
type: DataTypes.DATE,
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP'),
},
updatedAt: {
type: DataTypes.DATE,
defaultValue: Sequelize.literal('now()'),
},
deletedAt: {
type: DataTypes.DATE,
},
id: {
type: DataTypes.UUID,
primaryKey: true,
defaultValue: Sequelize.literal('uuid_generate_v4()'),
allowNull: false,
},
email: {
type: DataTypes.STRING,
allowNull: false,
},
login: {
type: DataTypes.STRING,
allowNull: false,
},
password: {
type: DataTypes.STRING,
allowNull: false,
},
lang: {
type: DataTypes.STRING,
defaultValue: "fr",
allowNull: false,
},
isActive: {
type: DataTypes.BOOLEAN,
defaultValue: true,
allowNull: false,
},
roles: {
type: DataTypes.JSONB,
allowNull: false,
},
resetPasswordToken: {
type: DataTypes.STRING,
},
emailValidationCode: {
type: DataTypes.STRING,
},
isEmailValidated: {
type: DataTypes.BOOLEAN,
allowNull: false,
},
isFullDonation: {
type: DataTypes.BOOLEAN,
defaultValue: true,
allowNull: false,
},
isSubscribedToClubNewsletter: {
type: DataTypes.BOOLEAN,
defaultValue: false,
allowNull: false,
},
isSubscribedToNewsletter: {
type: DataTypes.BOOLEAN,
defaultValue: false,
allowNull: false,
},
firstName: {
type: DataTypes.STRING,
},
lastName: {
type: DataTypes.STRING,
},
budgetInsightId: {
type: DataTypes.STRING,
},
budgetInsightToken: {
type: DataTypes.STRING,
},
budgetInsightSynchroStart: {
type: DataTypes.DATE,
},
paymentInformation: {
type: DataTypes.JSONB,
},
address: {
type: DataTypes.STRING,
},
postalCode: {
type: DataTypes.STRING,
},
city: {
type: DataTypes.STRING,
},
decathlonId: {
type: DataTypes.STRING,
},
decathlonPurchaseSynchroStart: {
type: DataTypes.DATE,
},
}, {
tableName: 't_e_user',
underscored: true,
});
// This section contains the relationships for this model. See: https://docs.forestadmin.com/documentation/v/v6/reference-guide/relationships#adding-relationships.
TEUser.associate = (models) => {
TEUser.belongsTo(models.tEClub, {
foreignKey: {
name: 'selectedClubIdKey',
field: 'selected_club_id',
},
as: 'selectedClub',
});
TEUser.hasMany(models.tERefreshToken, {
foreignKey: {
name: 'userIdKey',
field: 'user_id',
},
as: 'userTERefreshTokens',
});
TEUser.hasMany(models.tEUserDevice, {
foreignKey: {
name: 'userIdKey',
field: 'user_id',
},
as: 'userTEUserDevices',
});
TEUser.hasMany(models.tECashbackTransaction, {
foreignKey: {
name: 'userIdKey',
field: 'user_id',
},
as: 'userTECashbackTransactions',
});
TEUser.hasMany(models.tEUserWithdraw, {
foreignKey: {
name: 'userIdKey',
field: 'user_id',
},
as: 'userTEUserWithdraws',
});
TEUser.hasOne(models.tEToken, {
foreignKey: {
name: 'userIdKey',
field: 'user_id',
},
as: 'userTEToken',
});
};
return TEUser;
};
Thanks for the help,
Best regards,
Hugo