1
我正在嘗試使用ORMLite編寫查詢。我需要這個查詢檢查其他實體中的custommer的id。我怎麼能這樣做?嘗試使用ORMLite編寫查詢嗎?
實體
@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
}
查詢
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() + "");