package org.example.prototype.example;

import com.avaje.ebean.ExpressionList;
import org.example.BaseTestCase;
import org.example.domain.Contact;
import org.example.domain.Country;
import org.example.domain.Customer;
import org.example.domain.Order;
import org.example.domain.query.QContact;
import org.example.domain.query.QOrder;
import org.junit.Test;

import java.util.List;

/**
 */
public class ExampleQuery extends BaseTestCase {

  @Test
  public void test() {

//    QCustomer qc = new QCustomer();

    Country nz = Country.find.ref("NZ");


    ExpressionList<Contact> filter = new QContact()
        .email.like("some@foo%")
        .getExpressionList();
//
//
//    Customer.find
//        .where()
//        .billingAddress.country.equalTo(nz)
//        //.id.greaterThan(12)
//        //.name.ilike("rob")
//        .order()
//        .id.asc()
//        .contacts.filterMany(filter)
//        //.select("name")
//        //.fetch("contacts", "email")
//          //.query().filterMany("contacts").like("email","rob%@foo.com")
//        //.contacts.filterMany(where)
//        .findList();

//    Customer rob = new QCustomer()
//        .select("id, name")
//        .id.greaterThan(42)
//        .status.equalTo(Customer.Status.GOOD)
//        .name.ilike("Asd")
//        .name.isNull()
//        .billingAddress.country.code.equalTo("NZ")
//        .contacts.email.endsWith("@foo.com")
//        .findUnique();

  }

  @Test
  public void testOrder() {

    QOrder order = QOrder.alias();

    List<Order> orders = new QOrder()
        .select(order.orderDate, order.status)
        .customer.name.ilike("rob")
        .orderBy()
        .customer.name.asc()
        .orderDate.asc()
        .findList();

//        .shippingAddress.city.ieq("auckla")
//        .shippingAddress.country.code.eq("NZ")
//        .status.equalTo(Order.Status.APPROVED)
//        .orderDate.after(Date.valueOf("2015-01-20"))
//        .findList();
  }

}

@@ -278,32 +278,75 @@
 query.QContact;%0A
+import org.example.domain.query.QCustomer;%0A
 import org.examp
@@ -1524,18 +1524,16 @@
 rder ord
-er
  = QOrde
@@ -1542,16 +1542,55 @@
 alias();
+%0A    QCustomer cus = QCustomer.alias();
 %0A%0A    Li
@@ -1640,18 +1640,16 @@
 lect(ord
-er
 .orderDa
@@ -1655,18 +1655,16 @@
 ate, ord
-er
 .status)
@@ -1664,16 +1664,51 @@
 status)%0A
+        .customer.fetch(cus.name)%0A%0A
         

Add fetch() test