diff --git a/ebean-querybean/src/main/java/io/ebean/typequery/TQAssocBean.java b/ebean-querybean/src/main/java/io/ebean/typequery/TQAssocBean.java index e14a78d06..36758bee3 100644 --- a/ebean-querybean/src/main/java/io/ebean/typequery/TQAssocBean.java +++ b/ebean-querybean/src/main/java/io/ebean/typequery/TQAssocBean.java @@ -108,6 +108,18 @@ public abstract class TQAssocBean extends TQAssoc { return fetchWithProperties(FETCH_DEFAULT, properties); } + + /** + * Fetch this association with config for the type of fetch and the specified properties. + * + * @param config Fetch configuration to define the type of fetch to use + * @param properties The properties to fetch + */ + @SafeVarargs @SuppressWarnings("varargs") + public final R fetch(FetchConfig config, TQProperty... properties) { + return fetchWithProperties(config, properties); + } + /** * Eagerly fetch this association using a 'query join' loading the specified properties. */ diff --git a/ebean-querybean/src/test/java/org/querytest/QOrderTest.java b/ebean-querybean/src/test/java/org/querytest/QOrderTest.java index bcfa451ec..44627581d 100644 --- a/ebean-querybean/src/test/java/org/querytest/QOrderTest.java +++ b/ebean-querybean/src/test/java/org/querytest/QOrderTest.java @@ -1,6 +1,7 @@ package org.querytest; import io.ebean.DB; +import io.ebean.FetchConfig; import io.ebean.FetchGroup; import io.ebean.Query; import io.ebean.test.LoggedSql; @@ -8,6 +9,7 @@ import org.example.domain.Customer; import org.example.domain.Order; import org.example.domain.OrderDetail; import org.example.domain.otherpackage.PhoneNumber; +import org.example.domain.query.QContact; import org.example.domain.query.QCustomer; import org.example.domain.query.QOrder; import org.example.domain.query.QOrderDetail; @@ -26,10 +28,17 @@ public class QOrderTest { private static final QOrder or = QOrder.alias(); + private static final QContact co = QContact.alias(); + private static final FetchGroup fgC = QCustomer.forFetchGroup() .select(cu.name, cu.phoneNumber) .buildFetchGroup(); + private static final FetchGroup fgCustomerWithContacts = QCustomer.forFetchGroup() + .select(cu.name, cu.phoneNumber) + .contacts.fetch(FetchConfig.ofQuery(1000), co.firstName, co.lastName, co.email) + .buildFetchGroup(); + private static final FetchGroup fgNested1 = QOrder.forFetchGroup() .select(or.status, or.shipDate) .customer.fetch(fgC) @@ -70,6 +79,20 @@ public class QOrderTest { DB.delete(customer); } + @Test + void fetchQueryWithBatch() { + LoggedSql.start(); + + new QCustomer() + .select(fgCustomerWithContacts) + .findList(); + + final List sql = LoggedSql.stop(); + assertThat(sql).hasSize(2); + assertThat(sql.get(0)).contains("select t0.id, t0.name, t0.phone_number from be_customer t0"); + assertThat(sql.get(1)).contains("select t0.customer_id, t0.id, t0.first_name, t0.last_name, t0.email from be_contact t0 where"); + } + @Test public void fetchCache() {