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

Extra <modelClassName>_id column added in SELECT clause #1422

Closed
1 of 2 tasks
IonelLupu opened this issue Sep 6, 2022 · 1 comment
Closed
1 of 2 tasks

Extra <modelClassName>_id column added in SELECT clause #1422

IonelLupu opened this issue Sep 6, 2022 · 1 comment

Comments

@IonelLupu
Copy link

IonelLupu commented Sep 6, 2022

Issue

When using sequelize-typescript and doing .findAll() I get an error saying column.

import {Column, DataType, HasOne, Model, PrimaryKey, Table} from "sequelize-typescript"

@Table
export class User extends Model {
    @PrimaryKey
    @Column({type: DataType.UUID, defaultValue: DataType.UUIDV4})
    declare id: string

    @Column
    name: string

    @Column
    email: string
}

image

But, when using the normal sequelize package, the select works as expected and returns the correct data:

import {sequelize} from "../Database"
import {DataTypes} from "sequelize"

export const User = sequelize.define('user', {
    id: {
        type: DataTypes.UUID,
        defaultValue: DataTypes.UUIDV4,
        primaryKey: true
    },
    name: {
        type: DataTypes.STRING
    },
    email: {
        type: DataTypes.STRING
    }
})

I also created another model and it seems the extra column name is the model name plus _id.

Why is this extra column added and how can I remove it from selects?

Versions

  • "sequelize": "^6.21.4",
  • "sequelize-typescript": "^2.1.3",
  • "typescript": "^4.8.2"

Issue type

  • bug report
  • feature request

Actual behavior

Getting an error

Expected behavior

Should not select the <modelClassName>_id extra column

Steps to reproduce

Use sequelize-typescript to create a model and do .findAll() on that model.

Related code

import { Sequelize } from "sequelize-typescript";

export const sequelize = new Sequelize(process.env.DB_NAME, process.env.DB_USER, process.env.DB_PASSWORD, {
    host: process.env.DB_HOST,
    dialect: 'mysql',
    models: [__dirname + '/Models/**/*.{js,ts}'],
    logging: process.env.DB_LOGGING === "true",
    define: {
        timestamps: false,
        underscored: false,
        freezeTableName: true
    }
});
@IonelLupu
Copy link
Author

It seems I had another rogue entity in the project which had relationship properties that were pointing to the User class.

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

1 participant