Hello,
I am building out my CRUD API and am wondering if the ID column in an an update query should be modifiable.
I have the following entity:
@Entity()
export class Aircraft {
@PrimaryGeneratedColumn()
id: number;
@Column()
airlineId: number;
@ManyToOne(() => Airline, (airline) => airline.aircraft, { nullable: false })
@JoinColumn({ name: 'airlineId' })
airline: Airline;
}
Then, in my aircraft.service.ts, it can be updated like such:
async update(id: number, updateAircraftDto: UpdateAircraftDto): Promise<any> {
return await this.aircraftRepository
.createQueryBuilder()
.update(Aircraft)
.set(updateAircraftDto)
.returning('*')
.where('id = :id', { id })
.execute();
}
When I test this, I find that passing along any ID with my request will cause it to be updated in the database (so long as it's an integer). This seems pretty dangerous to me, but maybe it's the intended behavior? I am hoping someone can guide me on the proper pattern to use when updating an entity.
Thank you!