Distinct

Queries that return lists of fields will return duplicate values. The distinct function removes any duplicates from the returned list.

Given these types with a many-to-many relation between Customer and Address:

 type Customer struct {
  id int primaryKey
  relation addr Address many optional
  //other fields..
 } end
 type Address struct {
  id int primaryKey
  relation cust Customer many optional
  //other fields..
 } end

You can get a list of all customers who have an address. No customer will appear more than once in the list.

 let c1 = Address[true].cust.distinct()

You can get a list of distinct address for all customer's whose id > 1000. Even if several customers live at the same address, each address will appear only once in the query result.

 let a1 = Customer[id > 1000].addr.distinct()