Yes ok great, let’s try to work together on the subject then !
I have 8 services.
- BabySitting
- BikeRepair
- CarWash
- ElderlyAssist
- Flower
- Gardening
- HouseWork
- PressingAtCompany
In my order i have a serviceId that corresponds to a service.
I’ve also 8 table “Attributes” :
- OrderAttributeBabySitting
- OrderAttributeBikeRepair
- OrderAttributeCarWash
- OrderAttributeElderlyAssist
- OrderAttributeFlower
- OrderAttributeGardening
- OrderAttributeHouseWork
- OrderAttributePressingAtCompany
Each attribute table contains different element that corresponds to the information of the order. specific to its corresponding service.Obviously for an order of Flower I do not need the attributes of the service HouseWork, PressingAtCompany, …
The idea would therefore be to link the right attribute on each of the services.
Another small specificity, I lied above … In fact I have more than 8 services! Certain service does not have any attribute, the idea in which it would be to display nothing.
Here is some example between two services :
models/order.js
// 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 Order = sequelize.define('order', {
id: {
type: DataTypes.BIGINT,
autoIncrement: true,
primaryKey: true
},
userId: {
type: DataTypes.BIGINT,
allowNull: false,
},
companyId: {
type: DataTypes.BIGINT,
allowNull: false,
},
serviceId: {
type: DataTypes.BIGINT,
allowNull: false,
},
providerId: {
type: DataTypes.BIGINT,
allowNull: true,
defaultValue: null
},
status: {
type: DataTypes.INTEGER,
allowNull: false,
},
userComment: {
type: DataTypes.STRING,
allowNull: true,
defaultValue: null
},
amount: {
type: DataTypes.INTEGER,
defaultValue: 0,
allowNull: false,
},
deliveryDate: {
type: DataTypes.DATE,
allowNull: true,
defaultValue: null
},
createdAt: {
type: DataTypes.DATE,
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP'),
},
updatedAt: {
type: DataTypes.DATE,
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP'),
onUpdate: Sequelize.literal('CURRENT_TIMESTAMP')
},
}, {
tableName: 'Order',
});
// This section contains the relationships for this model. See: https://docs.forestadmin.com/documentation/v/v6/reference-guide/relationships#adding-relationships.
Order.associate = (models) => {
Order.belongsTo(models.user, {
foreignKey: 'userId',
});
Order.hasMany(models.orderDetail, {
foreignKey: 'orderId',
as: 'details',
});
Order.belongsTo(models.service, {
foreignKey: 'serviceId',
as: 'service',
});
Order.hasOne(models.orderPayment, {
foreignKey: 'orderId',
as: 'payment',
});
};
return Order;
};
models/service.js
// 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 Service = sequelize.define('service', {
name: {
type: DataTypes.STRING,
allowNull: false,
},
className: {
type: DataTypes.STRING,
allowNull: false,
},
categoryId: {
type: DataTypes.INTEGER,
allowNull: false,
},
externalLink: {
type: DataTypes.STRING,
},
createdAt: {
type: DataTypes.DATE,
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP'),
},
updatedAt: {
type: DataTypes.DATE,
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP'),
onUpdate: Sequelize.literal('CURRENT_TIMESTAMP')
},
}, {
tableName: 'Service',
});
// This section contains the relationships for this model. See: https://docs.forestadmin.com/documentation/v/v6/reference-guide/relationships#adding-relationships.
Service.associate = (models) => {
};
return Service;
};
models/order-attribute-baby-sitting.js
// 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 Service = sequelize.define('service', {
name: {
type: DataTypes.STRING,
allowNull: false,
},
className: {
type: DataTypes.STRING,
allowNull: false,
},
categoryId: {
type: DataTypes.INTEGER,
allowNull: false,
},
externalLink: {
type: DataTypes.STRING,
},
createdAt: {
type: DataTypes.DATE,
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP'),
},
updatedAt: {
type: DataTypes.DATE,
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP'),
onUpdate: Sequelize.literal('CURRENT_TIMESTAMP')
},
}, {
tableName: 'Service',
});
// This section contains the relationships for this model. See: https://docs.forestadmin.com/documentation/v/v6/reference-guide/relationships#adding-relationships.
Service.associate = (models) => {
};
return Service;
};
models/order-attribute-bike-repair.js
// 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 OrderAttributeBikeRepair = sequelize.define('orderAttributeBikeRepair', {
orderId: {
type: DataTypes.BIGINT,
primaryKey: true,
allowNull: false,
},
firstName: {
type: DataTypes.STRING,
allowNull: false,
},
lastName: {
type: DataTypes.STRING,
allowNull: false,
},
email: {
type: DataTypes.STRING,
allowNull: false,
},
indicMobile: {
type: DataTypes.STRING,
allowNull: false,
},
mobile: {
type: DataTypes.STRING,
allowNull: false,
},
streetNumber: {
type: DataTypes.STRING,
allowNull: false,
},
street: {
type: DataTypes.STRING,
allowNull: false,
},
locality: {
type: DataTypes.STRING,
allowNull: false,
},
postalCode: {
type: DataTypes.STRING,
allowNull: false,
},
country: {
type: DataTypes.STRING,
allowNull: false,
},
additionalAddress: {
type: DataTypes.STRING,
},
vehicle: {
type: DataTypes.INTEGER,
allowNull: false,
},
slots: {
type: DataTypes.STRING,
allowNull: false,
},
idOrderApi: {
type: DataTypes.INTEGER,
allowNull: false,
},
providerOrderNumber: {
type: DataTypes.STRING,
},
providerComment: {
type: DataTypes.STRING,
},
createdAt: {
type: DataTypes.DATE,
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP'),
},
updatedAt: {
type: DataTypes.DATE,
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP'),
onUpdate: Sequelize.literal('CURRENT_TIMESTAMP')
},
}, {
tableName: 'OrderAttributeBikeRepair',
});
// This section contains the relationships for this model. See: https://docs.forestadmin.com/documentation/v/v6/reference-guide/relationships#adding-relationships.
OrderAttributeBikeRepair.associate = (models) => {
};
return OrderAttributeBikeRepair;
};
Do not hesitate if you need clarification on the subject, or additional information. I will also start to try various things 