We have 2 entities: EstateIntegrationEntity and EstateEntity
When we try to use .findOne on the estateIntegrationRepository we get the following error:
[Nest] 5537 - 10/01/2020, 8:37:55 AM
[ExceptionsHandler] ER_DUP_FIELDNAME: Duplicate column name 'EstateIntegrationEntity_estate_id' +1590ms
QueryFailedError: ER_DUP_FIELDNAME: Duplicate column name 'EstateIntegrationEntity_estate_id'
at ...
We created a OneToOne relation from the EstateIntegrationEntity to the EstateEntity.
import { EstateEntity } from "src/estates/estate.entity";
import { Column, Entity, JoinColumn, OneToOne, PrimaryGeneratedColumn, RelationId } from "typeorm";
@Entity({ name: 'estate_integrations' })
export class EstateIntegrationEntity {
@PrimaryGeneratedColumn()
id: number;
@RelationId((estateIntegrationEntity: EstateIntegrationEntity) => estateIntegrationEntity.estate)
estate_id: number;
@OneToOne(() => EstateEntity, { eager: true })
@JoinColumn({ name: 'estate_id' })
estate: EstateEntity;
...
}
And a relation from the EstateEntity to the EstateIntegrationEntity :
import { EstateIntegrationEntity } from 'src/integrations/estate.integration.entity';
import { Column, Entity, JoinColumn, ManyToOne, OneToOne, PrimaryGeneratedColumn } from 'typeorm';
@Entity('estates')
export class EstateEntity {
@PrimaryGeneratedColumn()
id: number;
@Column('varchar' || null)
uuid: string;
@OneToOne(
() => EstateIntegrationEntity,
estate_integration => estate_integration.estate,
)
estate_integration: EstateIntegrationEntity;
}
This error only occurs with .findOne() and not with .find():
async findEstateById(id: string): Promise<EstateIntegrationEntity> {
return await this.estateIntegrationRepository.findOne({
where: {
external_id: id
}
});
}