mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
ADD: multiple to many outer joins cause wrong count in distinct count queries
This commit is contained in:
@@ -3,6 +3,7 @@ package org.tests.query.other;
|
||||
import io.ebean.BaseTestCase;
|
||||
import io.ebean.CountDistinctOrder;
|
||||
import io.ebean.CountedValue;
|
||||
import io.ebean.DB;
|
||||
import io.ebean.Ebean;
|
||||
import io.ebean.Query;
|
||||
import org.junit.Ignore;
|
||||
@@ -23,6 +24,32 @@ import java.util.List;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class TestQuerySingleAttribute extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void findSingleAttributesTwoToMany() {
|
||||
ResetBasicData.reset();
|
||||
Query<Customer> 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")
|
||||
.query();
|
||||
|
||||
List<Object> counted = query.findSingleAttributeList();
|
||||
CountedValue<String> robs = (CountedValue<String>)counted.get(0);
|
||||
assertThat(robs.getValue()).isEqualTo("Rob");
|
||||
assertThat(robs.getCount()).isEqualTo(1);
|
||||
|
||||
// TODO check correct future query
|
||||
assertThat(sqlOf(query)).contains("select r1.attribute_1, count(*) cnt"
|
||||
+ " from (select t1.id attribute_1 from main_entity_relation t0 left join main_entity t1 on t1.id = t0.id1 ) r1"
|
||||
+ " group by r1.attribute_1"
|
||||
+ " order by count(*) desc, r1.attribute_1");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void exampleUsage() {
|
||||
|
||||
Reference in New Issue
Block a user