Repository navigation
Description
Issue Creation Checklist
- I understand that my issue will be automatically closed if I don't fill in the requested information
- I have read the contribution guidelines
Bug Description
When saving a previously created object of a model using the build method the returned object of the save method includes the saved fields in the database but not the datatypes does not match with the saved datatype field/value.
For instance, if you build a Restaurant model, that includes some shipping costs with an object where shipping costs is a string, and then saved, these shipping costs are returned as a string, eventhough this field is a double in the database and it has been saved as a double.
Reproducible Example
req.body = { name: "Restaurant name", shippingCosts: "3.5", restaurantCategoryId: "1"}
const newRestaurant = Restaurant.build(req.body)
try {
const restaurant = await newRestaurant.save()
/* returned restaurant is: { createdAt: "2023-01-19T15:01:14.604Z",
updatedAt: "2023-01-19T15:01:14.604Z",
id: 16,
name: "RestaurantName",
shippingCosts: "3.5",
restaurantCategoryId: "1",
} */
res.json(restaurant)
catch (err) {
res.status(500).send(err)
}
What do you expect to happen?
I expect that datatypes of the subfields matches the datatypes of the table fields of the database.
What is actually happening?
Built/saved objects from an object where doubles/ints are represented as a string are returned as strings, instead of doubles/ints
Environment
- Sequelize version: 6.28.0 (macos)
- Node.js version: 14.17.6 (macos)
- If TypeScript related: TypeScript version:
- Database & Version: Mariadb 10.8.3_1 (macos)
- Connector library & Version: 3.3.2 (macos)
Would you be willing to resolve this issue by submitting a Pull Request?
- Yes, I have the time and I know how to start.
- Yes, I have the time but I will need guidance.
- No, I don't have the time, but my company or I are supporting Sequelize through donations on OpenCollective.
- No, I don't have the time, and I understand that I will need to wait until someone from the community or maintainers is interested in resolving my issue.
Indicate your interest in the resolution of this issue by adding the 👍 reaction. Comments such as "+1" will be removed.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsv8
Activity
ephys commentedon Jan 19, 2023
I could reproduce in mysql with an example as small as this:
This issue is also present in Sequelize 7, but we can only change the behavior in Sequelize 7 as it would be a breaking change