Skip to content

How to define ObjectID type column (other than _id) #2238

@thonythony

Description

@thonythony

Issue type:

[x] question
[ ] bug report
[ ] feature request
[ ] documentation issue

Database system/driver:

[ ] cordova
[x] mongodb
[ ] mssql
[ ] mysql / mariadb
[ ] oracle
[ ] postgres
[ ] sqlite
[ ] sqljs
[ ] react-native

TypeORM version:

[x] latest
[ ] @next
[ ] 0.x.x (or put your version here)

Steps to reproduce or a small repository showing the problem:

I have an entity :

@Entity()
export class RolePermission implements IRolePermission {
    @ObjectIdColumn() id?: ObjectID;

    @Column()
    @IsNotEmpty()
    roleId: ObjectID;

    @Column()
    @IsNotEmpty()
    permissionId: ObjectID;
}

The code compiles. But when I start my server, this error throws :

> node ./dist/server.js

error:  ColumnTypeUndefinedError: Column type for RolePermission#roleId is not defined and cannot be guessed. Make sure you have turned on an "emitDecoratorMetadata": true option in tsconfig.json. Also make sure you have imported "reflect-metadata" on top of the main entry file in your application (before any entity imported).If you are using JavaScript instead of TypeScript you must explicitly provide a column type.

I have turned on the option in my tsconfig.json and I import reflect-metadata at the top of my file server.ts.

I read the code about the decorator ObjectIdColumn and if I think it used only for primary use case, so it's not applicable for my need.

Thanks a lot for your help

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions