For query filters on to-many-relations one can use the special function contains() and defining a parameter which will automatically be used for iterating over all members of the to-manay-relation during query execution.
The following example uses a variable for a query:
// create query
Query q = pm.newQuery(Person.class);
// set a filter which persons to find
q.setFilter("addresses.contains(a) && a.city == \"London\"");
q.declareVariables("Address a");
q.declareImports("import com.intellibo.sample.query_with_variables.business.*");
// execute the query
Collection c = (Collection) q.execute();
The query is created for the class Person without a filter. The filter is applied using the setFilter() method instead, although it is possible to define the filter immediately within the newQuery() method.
The filter text contains the special function contains() for 1-n-relations and defines a variable a which is used in the further filter string. In the example above every Person will be found that has at least one Address in London.
Using the method declareVariables() you can define a as variable and declare its type. The type definition is made with the same method as known from Java. Multiple definitions are separated by a comma. If not using the full qualified class name while declaring parameters, the packages can be imported separately by using the method declareVariables().