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

[BUG] FK columns have wrong length when PrimaryGeneratedColumn('uuid') is used. #3604

Closed
AntonioAngelino opened this issue Feb 8, 2019 · 2 comments

Comments

@AntonioAngelino
Copy link
Contributor

Issue type:

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

Database system/driver:

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

TypeORM version:

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

Description

PrimaryGeneratedColumn('uuid') generates a VARCHAR(36) mysql column.
One-to-one, one-to-many and many-to-many relations generate VARCHAR(255) columns instead.

Steps to reproduce:

  • Create the following entities and check the generated DDL.
class Author {
    @PrimaryGeneratedColumn('uuid')
    id: string;
}

class Post {
    @PrimaryGeneratedColumn('uuid')
    id: string;

  @ManyToOne(type => Author)
  @JoinColumn()
  author: Author;
}
CREATE TABLE author
(
  id VARCHAR(36) NOT NULL PRIMARY KEY,
)
  ENGINE = InnoDB;

CREATE TABLE post
(
  id VARCHAR(36)  NOT NULL PRIMARY KEY,
 authorId VARCHAR(255) NULL,
CONSTRAINT FK_9466682df91534dd95e4dbaa616 FOREIGN KEY (authorId) REFERENCES author (id)
)
  ENGINE = InnoDB;
@tomtwo
Copy link

tomtwo commented Aug 14, 2019

In version 0.2.18 I'm still seeing an issue related to this when manually adding a userId field to my entity like this:

class Order extends BaseEntity {
  @ManyToOne(type => User, user => user.orders)
  user: User;

  @Column()
  userId: string;
}

The id column for User is a varchar(36), however the userId column in this other table becomes varchar(255). This can be overridden by using @Column({ length: 36}), but I guess it makes sense to fix this in typeorm?

@tomtwo
Copy link

tomtwo commented Aug 14, 2019

I want to be able to read the value of userId without joining the whole user. The pattern comes from the docs here:

https://github.com/typeorm/typeorm/blob/master/docs/relations-faq.md#how-to-use-relation-id-without-joining-relation

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

4 participants