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

Check whether the object passed is an entity #1914

Closed
1 of 4 tasks
alper opened this issue Feb 19, 2024 · 2 comments
Closed
1 of 4 tasks

Check whether the object passed is an entity #1914

alper opened this issue Feb 19, 2024 · 2 comments

Comments

@alper
Copy link

alper commented Feb 19, 2024

Is there an existing issue for this?

  • I have searched the existing issues

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

alper/nestjs-sample@2262a91

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?

  • macOS
  • Windows
  • Linux

Other

No response

@kamilmysliwiec
Copy link
Member

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

@alper
Copy link
Author

alper commented Feb 20, 2024

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

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

No branches or pull requests

2 participants