I have just started to read about ORMLite so I am still a beginner.
As far as I understand I can query objects using any of their persistent attributes.
For example, if I have the following classes:
@DatabaseTable
public class Bill {
@DatabaseField String code;
Client client;
List<Item> items;
}
@DatabaseTable
class Client {
@DatabaseField String name;
}
@DatabaseTable
class Item {
@DatabaseField String name;
}
(not sure how to annotate the client and items attributes in the class Bill).
In any case, a query like this will help me to obtain all the Bill objects with a particular code number:
QueryBuilder<Bill, String> queryBuilder = BillDao.queryBuilder();
Where<Bill, String> where = queryBuilder.where();
where.eq(BILL.NAME_CODE, "abc123");
PreparedQuery<Account> preparedQuery = queryBuilder.prepare();
My question is: what is the recommended way in ORMLite to write queries that have conditions in transitive relations of my model object ? for example “All the bills that include a particular item with a certain name”? or “All the clients that have bought an item with a certain name” ?.
Thanks in advance!.
Read Foreign Object Fields and Foreign Collections in ormLite docs.
Your relationship will be:
More information can be found in the code examples.