Answer the question
In order to leave comments, you need to log in
How to return attribute value instead of object in Sequlize?
const transaction = await Transaction.findByPk(1, {
attributes: ['id'],
include: [
{
model: TransactionStatus,
as: 'status',
attributes: ['name']
}
]
})
{id: 1, status: { name: "success" } }
{id: 1, status: "success" }
Answer the question
In order to leave comments, you need to log in
Solution:
The col() method
const transaction = await Transaction.findByPk(1, {
attributes: [[sequelize.col('transactionStatus.name'), 'status'], 'id'],
include: [
{
model: TransactionStatus,
as: 'transactionStatus',
attributes: []
}
]
})
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question