I'm trying write a query using ORMLite. I need this query check a id of custommer in other entity. How could I do it ?
Entities
@DatabaseTable(tableName = "custommer")
public class Custommer{
@DatabaseField(generatedId = true)
private Integer id;
@DatabaseField
private String name;
@DatabaseField
private Sale sale;
//gets sets
}
@DatabaseTable(tableName = "sale")
public class Sale{
@DatabaseField(generatedId = true)
private Integer id;
@DatabaseField
private Custommer custommer;
@DatabaseField
private Integer status;
//gets sets
}
Query
Custommer custommer = new Custommer();
custommer.setId(1);
custommer.setName("Fernando Paiva");
QueryBuilder<Sale, Integer> qb = saleDAO.queryBuilder();
Where where = qb.where();
where.eq("sale.custommer.id", custommer.getId());
where.and();
where.eq("sale.status", 1);
PreparedQuery<Sale> pq = qb.prepare();
List<Sale> list = saleDAO.query(pq);
Log.i("SALE LIST->", list.size() + "");
Are you trying to use OrmLite to check if the customer id is the same as the sale id and get all of the matching result? If so the below code will do that
Update:
After rereading your question I realized what you're trying to do
See this question for further details. Ormlite Foreign Entity Searching
You need to use JOIN
Here your example using Join:
Here the code