mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
Failing testcase that shows wipe of all children on save
When adding a newly saved bean (A) to another bean (B), all children in A are wiped on saving B.
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
package org.tests.cascade;
|
||||
|
||||
import io.ebean.BaseTestCase;
|
||||
import io.ebean.DB;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class TestOnlyKillOrphans extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
final COOne one = setup();
|
||||
|
||||
assertThat(one.getChildren()).hasSize(2);
|
||||
|
||||
CORoot root = new CORoot("P1", one);
|
||||
DB.insert(root);
|
||||
|
||||
// assert
|
||||
CORoot check = DB.find(CORoot.class, root.getId());
|
||||
assertThat(check.getOne().getChildren()).hasSize(2);
|
||||
DB.delete(check);
|
||||
}
|
||||
|
||||
private COOne setup() {
|
||||
COOne one = new COOne("P0");
|
||||
one.setChildren(createManies("M1", "M2"));
|
||||
DB.insert(one);
|
||||
return one;
|
||||
}
|
||||
|
||||
private List<COOneMany> createManies(String... names) {
|
||||
List<COOneMany> manies = new ArrayList<>();
|
||||
for (String name : names) {
|
||||
manies.add(new COOneMany(name));
|
||||
}
|
||||
return manies;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user