Bug 241 : QUERY LANGUAGE CHANGE: Add query.filterMany(...) method to filter *ToMany joins
Priority 
High
Reported Version 
 
Logged By 
Rob
Status 
Fixed
Fixed Version 
2.5.0
Assigned To 
 
Product 
Ebean - core
Duplicate Of 
 
Created 
11/03/2010
Updated 
11/03/2010
Type 
Bug
 
Attachments 
No attachments

This is related to Bug 239 which changed the implementation of a where clause predicate on a 'many' property (to filter the root results and not the 'many').

This change is the mechanism that allows a developer to filter the 'many' beans being fetched on a join (fetch join, query join or lazy join).

 
Rob 11 Mar 09:53
Example:

Note the filter on the orders... means we will only fetch the new orders made more recently than last week. It is a filter on the 'many' ... and not a filter on the 'root level' customers.

List<Customer> list = Ebean.find(Customer.class)
//  .join("orders", new JoinConfig().lazy())
//  .join("orders", new JoinConfig().query())
    .join("orders")
    .where().ilike("name","Rob%")
    .filterMany("orders")
        .eq("status", Order.Status.NEW)
        .gt("orderDate", lastWeek)
    .findList();

Rob 11 Mar 10:05
... produces the sql ...
<sql summary='Customer +many:orders' >
select c.id c0, c.status c1, c.name c2, ...
        , co.id c9, co.status c10, co.order_date c11, ...
from o_customer c
left outer join o_order co on co.kcustomer_id = c.id 
where lower(c.name) like ? and co.status = ?  and co.order_date > ?  
order by c.id
</sql>

So co.status = ? and co.order_date > ? ... are actually filtering the orders.

Rob 11 Mar 10:22
Fixed in HEAD

Fixed in HEAD.

woResponse

Upload a file