mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-09-20 03:16:42 +00:00
Fix refresh on soft-deleted beans
This commit is contained in:
@@ -188,7 +188,10 @@ final class DefaultBeanLoader {
|
||||
query.setLazyLoadProperty(ebi.lazyLoadProperty());
|
||||
if (draft) {
|
||||
query.asDraft();
|
||||
} else if (mode == SpiQuery.Mode.LAZYLOAD_BEAN && desc.isSoftDelete()) {
|
||||
} else if (desc.isSoftDelete()
|
||||
&& (mode == SpiQuery.Mode.LAZYLOAD_BEAN || mode == SpiQuery.Mode.REFRESH_BEAN)) {
|
||||
// include soft-deleted rows when lazy loading or refreshing so a
|
||||
// refresh() on a soft-deleted bean can reload it (issue #3641)
|
||||
query.setIncludeSoftDeletes();
|
||||
}
|
||||
if (embeddedOwnerIndex > -1) {
|
||||
|
||||
@@ -155,6 +155,33 @@ public class TestSoftDeleteBasic extends BaseTestCase {
|
||||
assertThat(findInclude).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRefreshSoftDeleted() {
|
||||
|
||||
EBasicSoftDelete bean = new EBasicSoftDelete();
|
||||
bean.setName("refreshSoftDeleted");
|
||||
DB.save(bean);
|
||||
|
||||
DB.delete(bean);
|
||||
|
||||
// obtain a handle to the soft-deleted bean
|
||||
EBasicSoftDelete softDeleted = DB.find(EBasicSoftDelete.class)
|
||||
.setId(bean.getId())
|
||||
.setIncludeSoftDeletes()
|
||||
.findOne();
|
||||
|
||||
assertThat(softDeleted).isNotNull();
|
||||
|
||||
// refresh() must not throw EntityNotFoundException for a soft-deleted bean (issue #3641)
|
||||
DB.refresh(softDeleted);
|
||||
|
||||
assertThat(softDeleted.getName()).isEqualTo("refreshSoftDeleted");
|
||||
assertThat(softDeleted.isDeleted()).isTrue();
|
||||
|
||||
// Cleanup created entity
|
||||
DB.deletePermanent(softDeleted);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindSoftDeleted() {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user