You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
Issue description
Property metadata override does not work when extending an entity class
Expected Behavior
In this example I expect
Extending.value
field to have metadata defined inExtending
, not inExtendable
, so in the databasevalue
field should have typedecimal
, notint
.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 beint
.Steps to reproduce
Create 2 entity classes, one of them should extend another and override parent field column metadata.
My Environment
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)
Are you willing to resolve this issue by submitting a Pull Request?
Yes, I have the time, and I know how to start.
The text was updated successfully, but these errors were encountered: