mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-10-24 23:56:36 +00:00
#288 - Exclude MaxRows FirstRow in findRowCount
This commit is contained in:
@@ -123,10 +123,8 @@ public class CQueryBuilder implements Constants {
|
||||
|
||||
// always set the order by to null for row count query
|
||||
query.setOrder(null);
|
||||
if (query.isRawSql()) {
|
||||
query.setFirstRow(0);
|
||||
query.setMaxRows(0);
|
||||
}
|
||||
query.setFirstRow(0);
|
||||
query.setMaxRows(0);
|
||||
|
||||
ManyWhereJoins manyWhereJoins = query.getManyWhereJoins();
|
||||
|
||||
@@ -281,9 +279,7 @@ public class CQueryBuilder implements Constants {
|
||||
OrmQueryDetail detail = new OrmQueryDetail();
|
||||
|
||||
// transfer PathProperties into OrmQueryDetail
|
||||
Iterator<String> pathIt = pathProps.getPaths().iterator();
|
||||
while (pathIt.hasNext()) {
|
||||
String path = pathIt.next();
|
||||
for (String path : pathProps.getPaths()) {
|
||||
Set<String> props = pathProps.get(path);
|
||||
detail.getChunk(path, true).setDefaultProperties(null, props);
|
||||
}
|
||||
|
||||
@@ -67,4 +67,29 @@ public class TestQueryRowCountWithMany extends BaseTestCase {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void testWithFirstRowsMaxRows() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
Long productId = 1L;
|
||||
|
||||
Query<Order> query = Ebean.find(Order.class)
|
||||
.fetch("details")
|
||||
.where().eq("details.product.id", productId)
|
||||
.setFirstRow(2)
|
||||
.setMaxRows(20)
|
||||
.orderBy("cretime asc");
|
||||
|
||||
LoggedSqlCollector.start();
|
||||
query.findRowCount();
|
||||
|
||||
List<String> sqlLogged = LoggedSqlCollector.stop();
|
||||
|
||||
Assert.assertEquals(1, sqlLogged.size());
|
||||
Assert.assertTrue(sqlLogged.get(0).contains("select count(*) from ( select distinct t0.id c0 from o_order t0 join o_order_detail u1 on u1.order_id = t0.id where u1.product_id = ? )"));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user