diff --git a/src/main/java/com/avaje/ebeaninternal/server/querydefn/OrmQueryProperties.java b/src/main/java/com/avaje/ebeaninternal/server/querydefn/OrmQueryProperties.java index e3b7a0dca..3ea4da639 100644 --- a/src/main/java/com/avaje/ebeaninternal/server/querydefn/OrmQueryProperties.java +++ b/src/main/java/com/avaje/ebeaninternal/server/querydefn/OrmQueryProperties.java @@ -227,6 +227,7 @@ public class OrmQueryProperties implements Serializable { */ public void setFilterMany(SpiExpressionList filterMany) { this.filterMany = filterMany; + this.markForQueryJoin = true; } /** @@ -269,7 +270,7 @@ public class OrmQueryProperties implements Serializable { return true; } // explicitly selected some properties - return included != null; + return included != null || filterMany != null; } /** diff --git a/src/test/java/com/avaje/tests/query/TestQueryFilterMany.java b/src/test/java/com/avaje/tests/query/TestQueryFilterMany.java index be4593553..44ba772a4 100644 --- a/src/test/java/com/avaje/tests/query/TestQueryFilterMany.java +++ b/src/test/java/com/avaje/tests/query/TestQueryFilterMany.java @@ -11,6 +11,7 @@ import org.junit.Test; import java.util.List; +import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; @@ -40,4 +41,24 @@ public class TestQueryFilterMany extends BaseTestCase { Ebean.refreshMany(customer, "orders"); } + + @Test + public void testNestedFilterMany() { + + ResetBasicData.reset(); + LoggedSqlCollector.start(); + Ebean.find(Customer.class) + .filterMany("contacts").isNotNull("firstName") + .filterMany("contacts.notes").istartsWith("title", "foo") + .findList(); + + List sql = LoggedSqlCollector.stop(); + + assertThat(sql).hasSize(3); + assertThat(sql.get(0)).contains(" from o_customer t0; --bind()"); + assertThat(sql.get(1)).contains(" from contact t0 where (t0.customer_id) in"); + assertThat(sql.get(1)).contains(" and t0.first_name is not null"); + assertThat(sql.get(2)).contains(" from contact_note t0 where (t0.contact_id) in"); + assertThat(sql.get(2)).contains(" and lower(t0.title) like"); + } }