Fix/select distinct cascaded fetch (#1015)

Fix/select distinct cascaded fetch with findSingleAttributeList() on associated property path
This commit is contained in:
Roland Praml
2017-04-30 23:07:35 +12:00
committed by Rob Bygrave
parent e51f7f11f1
commit f9c70d2a2b
4 changed files with 35 additions and 11 deletions
@@ -3,6 +3,8 @@ package org.tests.query.other;
import io.ebean.BaseTestCase;
import io.ebean.Ebean;
import io.ebean.Query;
import org.tests.model.basic.Contact;
import org.tests.model.basic.Customer;
import org.tests.model.basic.ResetBasicData;
import org.avaje.test.model.rawsql.inherit.ChildA;
@@ -162,6 +164,20 @@ public class TestQuerySingleAttribute extends BaseTestCase {
assertThat(cities).contains("Auckland").containsNull();
}
@Test
public void distinctWithCascadedFetch() {
ResetBasicData.reset();
Query<Contact> query = Ebean.find(Contact.class)
.setDistinct(true)
.fetch("customer.billingAddress","city");
List<String> cities = query.findSingleAttributeList();
assertThat(sqlOf(query)).contains("select distinct t2.city from contact t0 join o_customer t1 on t1.id = t0.customer_id left join o_address t2 on t2.id = t1.billing_address_id");
assertThat(cities).contains("Auckland").containsNull();
}
@Test
public void distinctSelectOnInheritedBean() {