question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Column name aliasing broke in v 0.2.29

See original GitHub issue

~~It looks like bug fix #6870 caused this regression. ~~ Edit from @imnotjames: It seems to be #4760

If you have a table with Primary key and another column with the same name, then the Primary ID name gets precedence. 0.2.28 was working correctly.

Issue Description

We have a table for example called Book which had a DB primary key in the db. But we don’t want to expose this to the users so we have created another column Book_id which has a UUID which we use in our API

@Entity({name: 'website_book'})
export class Book {
    @PrimaryGeneratedColumn({
        type: 'integer',
        name: 'id',     <========= 0.2.29 behavior 
    })
    oldBookId: number;

    @Column('int', {
        nullable: false,
        name: 'user_id',
    })
    user_id: number;

    @Column('character varying', {
        nullable: false,
        unique: true,
        length: 38,
        name: 'book_id',
    })
    id: string;    <========= 0.2.28 behavior 
}

Expected Behavior

" Book.id " should be mapped to (book_id column in the database)

Actual Behavior

" Book.id " is mapped to (id column in the database)

My Environment

Not os or env dependent issue

| TypeORM version : 0.2.29

Relevant Database Driver(s)

  • aurora-data-api
  • aurora-data-api-pg
  • better-sqlite3
  • cockroachdb
  • cordova
  • expo
  • mongodb
  • mysql
  • nativescript
  • oracle
  • postgres
  • react-native
  • sap
  • sqlite
  • sqlite-abstract
  • sqljs
  • sqlserver

Are you willing to resolve this issue by submitting a Pull Request?

I can help test the resolution

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:14 (10 by maintainers)

github_iconTop GitHub Comments

2reactions
ddehghancommented, Nov 9, 2020

Great. It worked. 😃 Thanks a lot @imnotjames

0reactions
midoelhawycommented, Nov 18, 2022

Hi everyone unfortunately, I have the same problem

TypeOrm use Class-model as table name in the final query

Code :

const banners = await AppDataSource.manager.find(Banner, {
                where: {
                    active: true
                }
            })

TYPE ORM QUERY RESULT :

SELECT 'Banner'.'id' AS 'Banner_id', 'Banner'.'image' AS 'Banner_image', 'Banner'.'description' AS 'Banner_description', 'Banner'.'type' AS 'Banner_type', 'Banner'.'price' AS 'Banner_price', 'Banner'.'link' AS 'Banner_link', 'Banner'.'active' AS 'Banner_active', 'Banner'.'customar_id' AS 'Banner_customar_id', 'Banner'.'updated_at' AS 'Banner_updated_at', 'Banner'.'created_at' AS 'Banner_created_at' FROM 'banners' 'Banner' WHERE ('Banner'.'active' = ?)'


Read more comments on GitHub >

github_iconTop Results From Across the Web

0.3.7 (2022-06-29) | TypeORM Docs
BREAKING CHANGES. we do not call JSON.stringify() to json/jsonb column types in Postgres. Instead, we delegate value directly to underlying pg driver.
Read more >
typeorm: CHANGELOG
minor breaking change on "conflict*" options - column names used are now automatically escaped.
Read more >
Change Log - Hail
The default behavior is False , which is a breaking change from the previous behavior to always copy output files ... This was...
Read more >
https://raw.githubusercontent.com/soda-kem/typeorm...
One must use `PrimaryColumnOptions` instead. * minor breaking change on "conflict*" options - column names used are now automatically escaped.
Read more >
ORA-00998: "must name this expression with a column alias"
As the error states, you need to make sure your columns all have valid identifiers (and although COUNT(NOMBRE) is a valid expression, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found