Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Class constructor Model cannot be invoked without 'new' #8757

Closed
eikebartels opened this issue Dec 6, 2017 · 2 comments
Closed

Class constructor Model cannot be invoked without 'new' #8757

eikebartels opened this issue Dec 6, 2017 · 2 comments

Comments

@eikebartels
Copy link

eikebartels commented Dec 6, 2017

What are you doing?

When I try to create a record for User I get the following issue.
Im using flow for typeing and bable for converting

const sequelize = new Sequelize(...




module.exports.models = models;

....




My babel config

{
  "presets": ["flow","es2015-node5"],
  "plugins": ["transform-class-properties"]
}

My Model

import { Model, Sequelize } from 'sequelize';

export default class User extends Model {
  constructor(){super();}
  id: number;
  // toke: string;
  username: string;
  email: string;
  // isAdmin: bool;

  static fields() {
    return {
        id: {
          type: Sequelize.UUID,
          defaultValue: Sequelize.UUIDV4,
          primaryKey: true,
          allowNull: false,
        },
        email: {
          type: Sequelize.STRING,
          allowNull: false,
        },
        password: {
          type: Sequelize.STRING,
          allowNull: false,
        }
      };
    }

What do you expect to happen?

Creating a database record

What is actually happening?

Error see below

Output, either JSON or SQL

{
  "name": "TypeError",
  "message": "Class constructor Model cannot be invoked without 'new'",
  "stack": "TypeError: Class constructor Model cannot be invoked without 'new'\n    at new User (/lib/models/User.js:10:17)\n    at Function.build (/node_modules/sequelize/lib/model.js:1937:12)\n    at Function.create (/node_modules/sequelize/lib/model.js:1988:17)\n    at UserController.signup (/driveddy/lib/controllers/UserActionController.js:33:34)\n    at /lib/routes/userActions.js:36:32\n    at dispatch (/node_modules/koa-compose/index.js:44:32)\n    at next (/node_modules/koa-compose/index.js:45:18)\n    at /node_modules/koa-router/lib/router.js:345:16\n    at dispatch (/node_modules/koa-compose/index.js:44:32)\n    at /node_modules/koa-compose/index.js:36:12\n    at dispatch (/node_modules/koa-router/lib/router.js:350:31)\n    at dispatch (/node_modules/koa/node_modules/koa-compose/index.js:42:32)\n    at next (/node_modules/koa/node_modules/koa-compose/index.js:43:18)\n    at parseBody.then.body (/node_modules/koa-bodyparser/index.js:74:14)\n    at <anonymous>\n    at process._tickCallback (internal/process/next_tick.js:188:7)",
  "status": 500
}

Dialect: postgres
Dialect version: "pg": "^7.4.0",
Database version: ?
Sequelize version: 4.26.0
Tested with latest release: YES

Note : I have tried this: #7840 and this #7840

@sushantdhiman
Copy link
Contributor

This is not how Model class should be used. Please check #6524 (comment)

@sushantdhiman
Copy link
Contributor

Also please note pg@7 is not supported #8043 , use pg@6 for now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants