'Sequelize does not include attributes (MySQL)
i am trying to create select with "custom" attribute.
Everything is working fine except that the "custom" attribute is not included.
Query is generated correctly so it should work but...\
Sequelize: 6.19.0
MySQL2: "^2.3.3"
DB options:
import { Options } from 'sequelize'
// eslint-disable-next-line import/prefer-default-export
export const development = {
url: process.env.MYSQL_URL,
options: {
minifyAliases: true,
logging: false,
pool: {
max: 4
},
dialect: "mysql",
dialectOptions: {
dateStrings: true,
typeCast: true,
timezone: "+02:00",
multipleStatements: false
},
timezone: '+02:00'
}
}
Select:
const currentPrices: any = await CurrentPrice.findAll({
limit: 10,
logging: true,
attributes: {
include:
[
[Sequelize.col("date"), "test"]
]
},
where:
filter
})
Generated query:
SELECT `item_id`, `city`, `sell_price_min`, `sell_price_max`, `buy_price_min`, `buy_price_max`, `date`, `date` AS `_0`
FROM `today_price` AS `currentPrice`
WHERE `currentPrice`.`date` >= CURRENT_TIME - interval 1 hour LIMIT 10;
Output:
{
"currentPrices": [
{
"item_id": "T4_CLOTH",
"city": "Bridgewatch",
"sell_price_min": 159,
"sell_price_max": 178,
"buy_price_min": 152,
"buy_price_max": 157,
"date": "2022-05-07 17:35:02"
}
]
}
Expected output:
{
"currentPrices": [
{
"item_id": "T4_CLOTH",
"city": "Bridgewatch",
"sell_price_min": 159,
"sell_price_max": 178,
"buy_price_min": 152,
"buy_price_max": 157,
"date": "2022-05-07 17:35:02"
"test": "2022-05-07 17:35:02"
}
]
}
EDIT//
So i tried add "raw: true" to my findall. The result contained "attribute include" but attribute name were "_0" instead of "test" Still trying to find solution.
EDIT//
Its started to work when i turned off "minifyAliases" as Anatoly wrote.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|