Skip to content

Instantly share code, notes, and snippets.

@ipolevoy
Created May 31, 2015 15:40
Show Gist options
  • Save ipolevoy/821e986c5c7deb28a90d to your computer and use it in GitHub Desktop.
Save ipolevoy/821e986c5c7deb28a90d to your computer and use it in GitHub Desktop.
@Test
public void shouldDeleteOnePatient(){
deleteAndPopulateTables("doctors", "patients", "doctors_patients");
Doctor doctor = Doctor.findById(1);
List<Patient> patients = doctor.getAll(Patient.class);
a(2).shouldBeEqual(patients.size());
doctor.remove(patients.get(0));
patients = doctor.getAll(Patient.class);
a(1).shouldBeEqual(patients.size());
}
@rivella50
Copy link

Another option would be to delete an entry in the join table by using the model of the join table.
Then both @Cache statements for Doctor and Patient could stay there :-)

@ipolevoy
Copy link
Author

ipolevoy commented Jun 1, 2015

@rivella50, the cached annotations works in such a way that in case, that whenever there is a destructive call like delete something, the framework will drop all associated caches. In this case, it will drop caches for all three tables. The test I wrote above is working as expected, so there must be something in your code. Are you using include() method when loading?

@rivella50
Copy link

Not anymore!
I will try to create a test class which should demonstrate what is not working correctly.
I'll post the code here when i'm ready

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment