FIX: subquery could not not have a where clause

This commit is contained in:
Jonas Pöhler
2021-07-29 17:09:24 +02:00
parent 4aef0ad459
commit 4cebb367de
3 changed files with 26 additions and 3 deletions
@@ -4,7 +4,6 @@ import io.ebean.BaseTestCase;
import io.ebean.Ebean;
import io.ebean.Query;
import io.ebeantest.LoggedSql;
import org.junit.Test;
import org.tests.model.basic.Customer;
import org.tests.model.basic.Order;
@@ -111,4 +110,17 @@ public class TestQueryExists extends BaseTestCase {
assertThat(sql).contains("not exists (");
}
@Test
public void testExistsNoWhere() {
ResetBasicData.reset();
Query<Order> subQuery = Ebean.find(Order.class).alias("sq").select("id");
Query<Customer> query = Ebean.find(Customer.class).alias("qt").where().notExists(subQuery).query();
query.findList();
String sql = query.getGeneratedSql();
assertThat(sql).contains("not exists (select sq.id from o_order sq)");
}
}
@@ -44,7 +44,17 @@ public class TestSubQuery extends BaseTestCase {
Query<Order> sq = DB.createQuery(Order.class).select("id").where()
.isIn("details.product.id", productIds).query();
DB.find(Order.class).where().isIn("id", sq).findList();
assertThat(DB.find(Order.class).where().isIn("id", sq).findList()).hasSize(2);
}
@Test
public void test_IsInNoWhere() {
ResetBasicData.reset();
Query<Order> sq = DB.createQuery(Order.class).select("id");
int expectedSize = DB.find(Order.class).findCount(); // expect everything
assertThat(DB.find(Order.class).where().isIn("id", sq).findList()).hasSize(expectedSize);
}
public void testCompositeKey() {