nestjs / typeorm

TypeORM module for Nest framework (node.js) 🍇
https://nestjs.com
MIT License
1.91k stars 206 forks source link

Check whether the object passed is an entity #1914

Closed alper closed 7 months ago

alper commented 7 months ago

Is there an existing issue for this?

Current behavior

Hi,

I found myself in a bit of a hole with the TypeORM integration. I followed the Trilon tutorial and cobbled together this:

export const dbConfig = {
    type: 'postgres',
    host: 'localhost',
    port: 5432,
    username: 'nestjs',
    password: 'nestjs',
    database: 'nestjsbooks',
    entities: [Book],
    migrations: [],
    synchronize: false,
}

The tutorial is this one (there the object is called Country) and has the exact same problem: https://github.com/TrilonIO/nest-data-source-agnostic/tree/main/src/countries

In my case it turns out that the Book I imported was the model and not the entity. In this case of course TypeORM can't really figure out what it should do.

It was fairly difficult to debug this oversight which seems like it has an obvious solution in a type checked environment like ours:

If you pass something to entities: that does not work, print out a message (or a warning).

Minimum reproduction code

https://github.com/alper/nestjs-sample/commit/2262a918a03492a91b6960f185baecc0096c2fcc

Steps to reproduce

No response

Expected behavior

I expect there to be an error message if you pass something that obviously does not work into the system.

Package version

10.0.1

NestJS version

No response

Node.js version

No response

In which operating systems have you tested?

Other

No response

kamilmysliwiec commented 7 months ago

Please, report this issue in the typeorm repository (typeorm/typeorm)

alper commented 7 months ago

Oh, I thought this decorator was Nest specific. Will do.