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.

inheritance - change primary key options

See original GitHub issue

Issue type:

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

Database system/driver:

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

TypeORM version:

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

Steps to reproduce or a small repository showing the problem:

class Base {
  @PrimaryGeneratedColumn()
  id:number;
}

@Entity()
class Demo extends Base {
  @PrimaryColumn({
    generated:false
  })
  id:number;
}

It created a table demo with primary key id auto incremented. generated:false is not working.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:2
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
Dilukacommented, Apr 13, 2019

@vlapo No, it’s not the same.

My propose

  1. I’m not inheriting table. the Base class is not going to sharing tables. It is the template to use in every tables.
  2. this is class inheritance. overriding property is legal.
  3. I don’t want to change type. Even if I change the type(still number, but maybe integer or float) it is still reasonable. (repeat it is not table inheritance. there is no @TableInheritance)
  4. I want to modify non-type options. in this demo, I’m just disabling the primary key auto generation.

Real scenario

I have multiple tables all with a primary id using the same type int. Most of those are auto increment. But there is one table using one-to-one relation with shared primary/foreign keys. So the child table’s (which has foreign key) primary key must be mandatory set the same value from the main table. So the generated need set to false.

0reactions
vlapocommented, Apr 13, 2019

I know it is not a same. I just want link this issue with #2865, in case someone will implement enhancement of inheritance (basically both problems are with inheritance and primary columns).

I understand your problem but it is not implemented. It is not possible define superclass with primary generated column, extends and disable auto generation in in subclass 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Inherited Class With Primary Key of Base Class and Another ...
I have a base class with id of type Int. I have a class B inherited of base class. Class B has an...
Read more >
Documentation: 15: 5.10. Inheritance - PostgreSQL
PostgreSQL implements table inheritance, which can be a useful tool for database designers. ... primary key, and foreign key constraints) are not inherited....
Read more >
Why is the type of inheritance required to be primary key (PK ...
Apparently, the answer to this question is pretty trivial: relationship types generally don't have their own primary key attributes.
Read more >
sql server - Primary keys due to inheritance
I am trying to design a database for postgrad office and we have a parent class "User" that has a username as a...
Read more >
Join inheritance type and composite primary keys — oracle-tech
Child]. When specifying @PrimaryKeyJoinColumns for an entity that has a composite primary key, a @PrimaryKeyJoinColumn must be specified for ...
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