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
Describe the bug
When a property has the same field name as the table, then that field will be filled with the primary key of the entity when loaded.
To Reproduce
This test should show the issue:
import{AbstractNamingStrategy,Collection,Entity,EntityRepository,IdentifiedReference,Logger,ManyToMany,ManyToOne,MikroORM,OneToMany,OneToOne,PrimaryKey,PrimaryKeyProp,PrimaryKeyType,Property,Reference}from'@mikro-orm/core';import{AbstractSqlDriver,SchemaGenerator}from'@mikro-orm/knex';classTestNamingStrategyextendsAbstractNamingStrategy{classToTableName(entityName: string): string{thrownewError('Method not implemented.');}propertyToColumnName(propertyName: string): string{returnpropertyName;}referenceColumnName(): string{thrownewError('Method not implemented.');}joinColumnName(propertyName: string): string{returnpropertyName;}joinTableName(sourceEntity: string,targetEntity: string,propertyName?: string|undefined): string{thrownewError('Method not implemented.');}joinKeyColumnName(entityName: string,referencedColumnName?: string|undefined): string{returnentityName.toLocaleLowerCase();}}
@Entity({tableName: 'name'})className{
@PrimaryKey()id!: number;
@Property({fieldName: 'name'})realName!: string;
@ManyToMany({entity: 'User',pivotTable: 'userNames',mappedBy: 'names'})users=newCollection<User>(this);constructor(name: string){this.realName=name;}}
@Entity({tableName: 'user'})classUser{
@PrimaryKey()id!: number;
@ManyToMany({entity: 'Name',pivotTable: 'userNames'})names=newCollection<Name>(this);}describe('preserve data fields',()=>{letorm: MikroORM<AbstractSqlDriver>;constlog=jest.fn();beforeAll(async()=>{orm=awaitMikroORM.init({entities: [User,Name],dbName: `mikro_orm_test_pivot_fields_wa`,type: 'postgresql',cache: {enabled: false},namingStrategy: TestNamingStrategy,});awaitnewSchemaGenerator(orm.em).ensureDatabase();});beforeEach(async()=>{awaitorm.getSchemaGenerator().dropSchema();awaitorm.getSchemaGenerator().createSchema();});afterAll(()=>orm.close(true));test('preserves data fields with same name as table',async()=>{constuser=orm.em.create<User>(User,{});constname=orm.em.create<Name>(Name,{id: 42,realName: 'this is my name'});user.names.add(name);awaitorm.em.persistAndFlush([user,name]);// Ensure we don't get the data from the existing identity map.orm.em.clear();constentity=awaitorm.em.findOneOrFail<User>(User,user,{populate: ['names'],refresh: true});expect(entity.names[0].realName).toEqual('this is my name');});});
Expected behavior
Fields should always receive the data from the correct column.
Versions
Dependency
Version
node
14
typescript
4
mikro-orm
HEAD
your-driver
postgresql
The text was updated successfully, but these errors were encountered:
Describe the bug
When a property has the same field name as the table, then that field will be filled with the primary key of the entity when loaded.
To Reproduce
This test should show the issue:
Expected behavior
Fields should always receive the data from the correct column.
Versions
The text was updated successfully, but these errors were encountered: