#835 - Tests for - A query that includes a fetch() of a many that is @SoftDelete where all the rows are soft deleted returns incorrect results

This commit is contained in:
Rob Bygrave
2016-10-17 20:51:22 +13:00
parent 37804bd083
commit 3161e24677
2 changed files with 57 additions and 0 deletions
@@ -202,4 +202,33 @@ public class TestSoftDeleteBasic extends BaseTestCase {
assertThat(fetchAllWithLazy.getChildren()).hasSize(3);
}
@Test
public void testWhenAllChildrenSoftDeleted() {
EBasicSoftDelete bean = new EBasicSoftDelete();
bean.setName("softDelChildren");
bean.addChild("child1", 10);
bean.addChild("child2", 20);
Ebean.save(bean);
Ebean.deleteAll(bean.getChildren());
Query<EBasicSoftDelete> query = Ebean.find(EBasicSoftDelete.class)
.setId(bean.getId())
.fetch("children");
EBasicSoftDelete found = query.findUnique();
String generatedSql = sqlOf(query);
if (isPlatformBooleanNative()) {
assertThat(generatedSql).contains("left join ebasic_sdchild t1 on t1.owner_id = t0.id and coalesce(t1.deleted,false)=false");
assertThat(generatedSql).contains("coalesce(t0.deleted,false)=false");
} else {
assertThat(generatedSql).contains("left join ebasic_sdchild t1 on t1.owner_id = t0.id and coalesce(t1.deleted,0)=0");
assertThat(generatedSql).contains("coalesce(t0.deleted,0)=0");
}
assertThat(found).isNotNull();
}
}
@@ -2,6 +2,7 @@ package com.avaje.tests.softdelete;
import com.avaje.ebean.BaseTestCase;
import com.avaje.ebean.Ebean;
import com.avaje.ebean.Query;
import com.avaje.tests.model.softdelete.ESoftDelBook;
import com.avaje.tests.model.softdelete.ESoftDelUser;
import org.junit.Test;
@@ -77,4 +78,31 @@ public class TestSoftDeleteBook extends BaseTestCase {
assertThat(lendBy.isDeleted()).isTrue();
}
@Test
public void test_fetch_whenAllManySoftDeleted() {
// Create users
ESoftDelUser user1 = new ESoftDelUser("user1");
Ebean.save(user1);
ESoftDelUser user2 = new ESoftDelUser("user2");
Ebean.save(user2);
// Create books
ESoftDelBook book1 = new ESoftDelBook("book3");
book1.setLendBy(user1);
book1.setLendBys(Arrays.asList(user1, user2));
Ebean.save(book1);
Ebean.delete(user1);
Ebean.delete(user2);
Query<ESoftDelBook> query = Ebean.find(ESoftDelBook.class)
.setId(book1.getId())
.fetch("lendBys");
ESoftDelBook found = query.findUnique();
assertThat(found).isNotNull();
}
}