I have an optional OneToOne relation between Class User and Profile. I've got two instances of Profile one has a user and the other hasn't.
Ok, here is the problem, when I try to execute the 'createOne()' using the existing profile that hasn't a User and the parameter Join User is settled to eager, the function 'this.base.updateOneBase(req, profile);' executes an update in the profile trying to insert the User of the other existing profile without me sending this user, and then an error is returned due to the OneToOne restriction.
AbstractEntity:
export abstract class AbstractEntity<T extends AbstractDto = AbstractDto> {
@PrimaryGeneratedColumn('uuid')
id: string;
@CreateDateColumn({
type: 'timestamp without time zone',
name: 'created_at',
})
createdAt: Date;
@UpdateDateColumn({
type: 'timestamp without time zone',
name: 'updated_at',
})
updatedAt: Date;
@Exclude()
abstract dtoClass: new (entity: AbstractEntity, options?: any) => T;
toDto(options?: any) {
return UtilsService.toDto(this.dtoClass, this, options);
}
I made an override in the createOne function of the Profile Controller to check if the profile already exists by the username field. If the profile exists, the update base function is executed. If not, a new profile is created(Ignore the business logic. It's just for show).
I have an optional OneToOne relation between Class User and Profile. I've got two instances of Profile one has a user and the other hasn't.
Ok, here is the problem, when I try to execute the 'createOne()' using the existing profile that hasn't a User and the parameter Join User is settled to eager, the function 'this.base.updateOneBase(req, profile);' executes an update in the profile trying to insert the User of the other existing profile without me sending this user, and then an error is returned due to the OneToOne restriction.
AbstractEntity:
}
User:
Profile:
I made an override in the createOne function of the Profile Controller to check if the profile already exists by the username field. If the profile exists, the update base function is executed. If not, a new profile is created(Ignore the business logic. It's just for show).
Project Link: https://github.com/sthormio/nestjsx-crud-issue