Skip to content

should be able to delete target instances based on filters in HasManyThrough relation #5852

@agnes512

Description

@agnes512

Steps to reproduce

a Doctor has many Patients through Appointment, the relation called patients.

Doctor :           [{id: 1, dec: 'doctor'}]
Appointment:       [{doctorId: 1, patientId: 1}, {doctorId: 1, patientId: 2}]
Patient:           [{id: 1, name: 'p1'}, {id: 2, name: 'p2'}]

Current Behavior

// delete all patients that belongs to doctor id 1 where the patient name is p2
doctorRepo.patients(1).delete({name: 'p2'});

The target p2 gets deleted, but patient p1 is no longer traversable as the through model Appointment{doctorId: 1, patientId: 1} gets deleted too.

Expected Behavior

Should delete the related through models instead of deleting all throughs that belong to the same source key.

Acceptance Criteria

  • redesign the delete method in hasManyThrough repository
  • add tests to verify the new behaviour

Metadata

Metadata

Assignees

Labels

RelationsModel relations (has many, etc.)bug

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions