loopback-next
loopback-next copied to clipboard
[@loopback/sequelize] Cannot use Loopback entity “array” property type with MySQL / MariaDB datasource
Describe the bug
If you try to save or update an entity with an “array” property, it will lead to a mysqld error for invalid data. This is caused by unserialized arrays being passed as parameters through the mysql2 driver.
Relates to: https://github.com/loopbackio/loopback-next/issues/9598
Logs
No response
Additional information
As a workaround, I tried changing the Loopback entity array properties to the “object” type but that causes a conflict with the Loopback request validation expecting an array type to be passed in the request.
Serializing arrays to a string for non-Postgres dialects at the Sequelize extension layer is likely the most straightforward way to resolve this.
References:
- https://sequelize.org/docs/v6/other-topics/other-data-types/#arrays-postgresql-only
- https://stackoverflow.com/questions/41860792/how-can-i-have-a-datatype-of-array-in-mysql-sequelize-instance
Reproduction
N/A