Skip to content

Commit e2c12de

Browse files
committed
fix(tasks): clear assignee relation when updating assignedTo FK
TypeORM caches the loaded relation object. When updating only the FK column (assignedTo), the cached assignee relation would override the new FK value during save. Clearing the relation ensures the new assignedTo value is properly persisted.
1 parent 7a13564 commit e2c12de

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

src/tasks/tasks.service.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,14 @@ export class TasksService {
7575

7676
async update(id: string, updateTaskDto: UpdateTaskDto): Promise<Task> {
7777
const task = await this.findOne(id);
78+
79+
// ROOT FIX: Clear the assignee relation when assignedTo changes
80+
// This ensures TypeORM properly updates the FK and doesn't cache stale relation
81+
if (updateTaskDto.assignedTo !== undefined) {
82+
// Clear the loaded relation so TypeORM uses the new FK value
83+
task.assignee = null as any;
84+
}
85+
7886
Object.assign(task, updateTaskDto);
7987
const updatedTask = await this.taskRepository.save(task);
8088

0 commit comments

Comments
 (0)