Issue on response raw: true #17671
Unanswered
aksamitsah
asked this question in
Help & Questions
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
How to achive this
after making raw: true this give me flat array but i need custom name how to achieve this
module.exports = (sequelize, DataTypes) => {
const Stock = sequelize.define(
'Stock',
{
id: {
type: DataTypes.UUID,
primaryKey: true,
defaultValue: DataTypes.UUIDV4,
},
medicineId: {
type: DataTypes.UUID,
allowNull: false,
references: {
model: 'medicines', // Foreign key to Medicine table
key: 'id',
},
indexes: [{ using: 'BTREE' }],
},
supplierId: {
type: DataTypes.UUID,
allowNull: false,
references: {
model: 'suppliers', // Foreign key to Supplier table
key: 'id',
},
indexes: [{ using: 'BTREE' }],
},
batchNo: {
type: DataTypes.STRING,
allowNull: false,
},
expDate: {
type: DataTypes.DATE,
allowNull: false,
},
quantityAvailable: {
type: DataTypes.INTEGER,
allowNull: false,
},
quantityAdded: {
type: DataTypes.INTEGER,
allowNull: false,
},
cPrice: {
type: DataTypes.DECIMAL(10, 2),
allowNull: true,
},
sPrice: {
type: DataTypes.DECIMAL(10, 2),
allowNull: true,
},
discount: {
type: DataTypes.DECIMAL(10, 2),
allowNull: true,
},
notes: {
type: DataTypes.STRING,
allowNull: true,
},
isActive: {
type: DataTypes.INTEGER,
allowNull: false,
defaultValue: 1,
},
},
{
tableName: 'stocks',
timestamps: true,
},
);
// Define associations
Stock.associate = (models) => {
Stock.belongsTo(models.Medicine, { foreignKey: 'medicineId', as: 'medicine' });
Stock.belongsTo(models.Supplier, { foreignKey: 'supplierId', as: 'supplier' });
};
return Stock;
};
thanks in advance
Beta Was this translation helpful? Give feedback.
All reactions