我试着编写使用ORMLite查询。 我需要这个查询检查custommer的ID在其他实体。 我怎么能这样做呢?
实体
@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() + "");