sequelize-typescript icon indicating copy to clipboard operation
sequelize-typescript copied to clipboard

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

Open ColtraneNadler opened this issue 4 years ago • 4 comments

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

  • [X] bug report
  • [ ] feature request

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.

ColtraneNadler avatar Feb 23 '21 15:02 ColtraneNadler

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

dorijanf avatar Apr 13 '21 12:04 dorijanf

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

leonardo2204 avatar Jun 02 '21 22:06 leonardo2204

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

simonstey avatar Nov 26 '21 06:11 simonstey

use this

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

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

raeddayah avatar Dec 21 '22 13:12 raeddayah