-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Closed
Description
What you are doing?
I'm using raw queries to get data between some tables.
//models/order.js
module.exports = function (sequelize, DataTypes) {
var Order = sequelize.define('order', {
orderDescription: {
type: DataTypes.STRING(250),
allowNull: false,
field: "order_description"
},
siteId: {
type:DataTypes.STRING(12),
allowNull: false,
field: "site_id"
}
},
{
timestamps: true,
underscored: true,
freezeTableName: true
});
return Order;
};
//Woks perfect
models.order.findOne({ where: where }).then(function(orderDB){
/*
order.toJSON() === {
orderDescription: "my order",
siteId: "1234"
}
*/
});
//******* ERROR ******* Getting orders using Raw queries
sequelize.query('SELECT * FROM orders...', {
type: models.sequelize.QueryTypes.SELECT,
model: models.order,
raw: true
}).then(function(orders){
/*
orders === [
{
order_description: "my order", <== ERROR PROPERTY NAME
site_id : "1234"
}
]
*/
})
What do you expect to happen?
Convert the query respecting the model using the property names from the Sequelize Model.
What is actually happening?
The query return the column names from the database instead of property names from the Sequelize Model.
Dialect: postgres
Database version: 9.5.3
Sequelize version: 3.23.6
bradisbell
Metadata
Metadata
Assignees
Labels
No labels