sequelize / sequelize-typescript

Decorators and some other features for sequelize
MIT License
2.78k stars 280 forks source link

TypeError: Class constructor User cannot be invoked without 'new' #924

Open ColtraneNadler opened 3 years ago

ColtraneNadler commented 3 years ago

Issue

TypeError: Class constructor User cannot be invoked without 'new'

Versions

"routing-controllers": "^0.9.0",
"sequelize": "^6.5.0",
"sequelize-typescript": "^2.1.0",
"tsc": "^1.20150623.0",
"tslint": "^6.1.3"

Issue type

Actual behavior

TypeError: Class constructor User cannot be invoked without 'new'

Expected behavior

It should return the rows with the included rows

Steps to reproduce

Query with an include

Related code

The issue when I use include. Im using routiing-controllers Snippet from the route handler that caused this particular error

const posts = await Post.findAll({
        where: {community_id: community},
    include: [User],
    order: [['created_at', 'DESC']]
})

return posts;

Any ideas on how to fix? I'm following the documentation directly.

dorijanf commented 3 years ago

@ColtraneNadler Have you ever managed to find a solution to this?

leonardo2204 commented 3 years ago

I'm also looking for a solution here. I'm using es target es2017

simonstey commented 2 years ago

fwiw, this post solved it for me https://stackoverflow.com/a/68602295

raeddayah commented 1 year ago

use this

const posts = await Post.findAll({ where: {community_id: community}, include: [User], order: [['created_at', 'DESC']] })

return posts.get({ plain: true });