Created
May 31, 2015 15:40
-
-
Save ipolevoy/821e986c5c7deb28a90d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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()); | |
} |
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 :-)
@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?
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
When i do something very similar in my code/database the second getAll request sometimes (!!!) gets the same number of Patients as before the remove call, even if the row is gone in database...
I really don't know what's going on here.
It seems that disabling @Cache for both models solves it, but since one of the two models are used quite often i wouldn't like losing the caching feature there.
Can you confirm that having @Cache enabled can lead to problems here ?