You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
it happens that sequelize-typescript doesn't expect a Sequelize literal on virtual constructor and when I implemented the code I found this error:
Type '[Literal, string]' is not assignable to type 'string'
Expected behavior
No Typescript error
Steps to reproduce
Implement a model with 1-to-N relation and include a virtual field with a subquery using a Sequelize.literal like this:
@Column({type: DataType.VIRTUAL(DataType.INTEGER,[[Sequelize.literal('(SELECT COUNT("Subthings"."id") FROM "Subthings" WHERE "Subthings"."parentId" = "Thing"."id")'),'thingCount']])})
thingCount: number
Related code
@Column({type: DataType.VIRTUAL(DataType.INTEGER,[//@ts-expect-error - sequelize-typescript doesn't support Sequelize.literal type[Sequelize.literal('(SELECT COUNT("Subthings"."id") FROM "Subthings" WHERE "Subthings"."parentId" = "Thing"."id")'),'thingCount']])})
thingCount: number
The text was updated successfully, but these errors were encountered:
Issue
It would be nice to support Sequelize.literal on virtual subqueries, because it's a really common use-case.
Versions
Issue type
Actual behavior
I'm trying to perform a subquery on a virtual field similar to the one in the following comment:
sequelize/sequelize#4942 (comment)
it happens that sequelize-typescript doesn't expect a Sequelize literal on virtual constructor and when I implemented the code I found this error:
Type '[Literal, string]' is not assignable to type 'string'
Expected behavior
No Typescript error
Steps to reproduce
Implement a model with 1-to-N relation and include a virtual field with a subquery using a Sequelize.literal like this:
Related code
The text was updated successfully, but these errors were encountered: