'TypeORM. Cannot perform update query because update values are not defined. Call \"qb.set(...)\" method to specify updated values
I am new to TypeORM. I'm using MySQL DB and ExpressJS app.
I have 2 entities: User and Client. There's one-to-one relationship between them. Client has foreign key. I get following error when I save a client:
Cannot perform update query because update values are not defined. Call "qb.set(...)" method to specify updated values
User Entity:
export class User extends BaseEntity {
@PrimaryGeneratedColumn()
id: number
@Column()
role: string
@Column()
email: string
@Column()
password: string
@Column({ default: '' })
avatar: string
@Column()
firstName: string
@Column()
lastName: string
@Column()
fullName: string
@Column({ default: '' })
phone: string
@Column({ type: 'text', nullable: true })
description: string
@Column({ nullable: true })
age: number
@OneToOne(_type => Freelancer, freelancer => freelancer.user, { nullable: true })
freelancer: Freelancer
@OneToOne(_type => Client, client => client.user, { nullable: true })
client: Client
}
Client Entity:
@Entity()
export class Client extends BaseEntity {
@PrimaryGeneratedColumn()
id: number
@Column()
companyName: string
@ManyToOne(_type => Position, position => position.clients)
position: Position
@OneToOne(_type => ClientReview, clientReview => clientReview.client, { nullable: true })
@JoinColumn()
review: ClientReview
@OneToMany(_type => Project, project => project.client, { nullable: true })
projects: Project[]
@OneToOne(_type => User, user => user.client)
@JoinColumn()
user: User
}
Code in auth.service, where I save client. Just overview:
const user = userRepository.create({
email,
password: hashedPassword,
role,
description,
firstName,
lastName,
fullName: `${firstName} ${lastName}`,
phone
})
const clientRepository = getRepository(Client)
const positionRepository = getRepository(Position)
const positionEntity = await positionRepository.findOne({ id: position.id })
const client = clientRepository.create({
companyName,
position: positionEntity,
user
})
await userRepository.save(user)
await clientRepository.save(client)
The problem is in user column of Client entity, as when I remove it, everything works, but Client and User are saved separately and do not have any relation between each other, obviously.
So, my questions are What I did wrong and How should I fix it? Thanks for the answer beforehand
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
