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

Property metadata override does not work when extending an entity class #10895

Open
18 tasks
titovb opened this issue May 19, 2024 · 0 comments · May be fixed by #10896
Open
18 tasks

Property metadata override does not work when extending an entity class #10895

titovb opened this issue May 19, 2024 · 0 comments · May be fixed by #10896

Comments

@titovb
Copy link

titovb commented May 19, 2024

Issue description

Property metadata override does not work when extending an entity class

Expected Behavior

@Entity()
class Extendable {
  @PrimaryGeneratedColumn()
  id: number;
  
  @Column({ type: 'int' })
  value: number;
}

@Entity()
class Extending extends Extendable {
  @Column({ type: 'decimal' })
  value: number;

  @Column({ type: 'int' })
  otherValue: number;
}

const dataSource = new DataSource({
  // any other configuration
  synchronize: true,
  entities: [Extending],
});
dataSource.initialize();

In this example I expect Extending.value field to have metadata defined in Extending, not in Extendable, so in the database value field should have type decimal, not int.

Actual Behavior

TypeORM applies metadata from parent class field for descendant class field even if descendant overrides that field metadata.
So, in example from "Expected Behaviour", in the database the type of the field value would be int.

Steps to reproduce

Create 2 entity classes, one of them should extend another and override parent field column metadata.

My Environment

Dependency Version
Operating System
Node.js version 20.13.1
Typescript version 5.4.5
TypeORM version 0.3.20

Additional Context

While consuming and processing metadata, MetadataArgsStorage.filterByTargetAndWithoutDuplicateProperties method is used, which save first occurance of target metadata and ignores any other. But, I think, that this function should consider overrides of metadata and set higher priority for metadata from descendants.

Relevant Database Driver(s)

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

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

Yes, I have the time, and I know how to start.

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

Successfully merging a pull request may close this issue.

1 participant