diff --git a/ebean-core/src/test/java/org/tests/query/other/TestQuerySingleAttribute.java b/ebean-core/src/test/java/org/tests/query/other/TestQuerySingleAttribute.java index 8ecaae8a9..a5cd5d481 100644 --- a/ebean-core/src/test/java/org/tests/query/other/TestQuerySingleAttribute.java +++ b/ebean-core/src/test/java/org/tests/query/other/TestQuerySingleAttribute.java @@ -28,20 +28,33 @@ public class TestQuerySingleAttribute extends BaseTestCase { @Test public void findSingleAttributesTwoToMany() { ResetBasicData.reset(); + // Query without ors with equals causing joins, only one Customer with name Rob exists + Query query0 = DB.find(Customer.class) + .select("name") + .setCountDistinct(CountDistinctOrder.COUNT_DESC_ATTR_ASC) + .where() + .eq("name", "Rob") + .query(); + + CountedValue robs0 = (CountedValue) query0.findSingleAttributeList().get(0); + assertThat(robs0.getValue()).isEqualTo("Rob"); + assertThat(robs0.getCount()).isEqualTo(1); + + // Query with or with equals causing joins Query query = DB.find(Customer.class) .select("name") - //.apply(toFetchPath("name")) .setCountDistinct(CountDistinctOrder.COUNT_DESC_ATTR_ASC) .where() .eq("name", "Rob") .or() .eq("orders.status", Order.Status.NEW) .eq("contacts.firstName", "Fred1") + .endOr() .query(); - List counted = query.findSingleAttributeList(); - CountedValue robs = (CountedValue)counted.get(0); + CountedValue robs = (CountedValue) query.findSingleAttributeList().get(0); assertThat(robs.getValue()).isEqualTo("Rob"); + // only one Customer named rob exists, but 7 is returned for the amount of Customers named Rob assertThat(robs.getCount()).isEqualTo(1); // TODO check correct future query