Skip to content Skip to sidebar Skip to footer

How To Build Query With Selecting By Value Of Foreign Object's Field

What is the best way for querying by using the value of foreign object's field? Suppose I have these three classes. UnitResult class which describes amount of Units: @DatabaseTable

Solution 1:

So how can I query all UnitResult where Unit type is UnitType.JUICES?

The way to do this in ORMLite is to use the `Where.in(...) with a sub-query:

// setup oursub-queryontheUnittablefirstQueryBuilder<Unit,Integer> uQb = unitDao.queryBuilder();
uQb.where().eq(Unit.TYPE_FIELD_NAME, UnitType.JUICES);
// outer query on UnitResult table
QueryBuilder<UnitResult,Integer> urQb = unitResultDao.queryBuilder();
// in using the sub-queryurQb.where().in(UnitResult.UNIT_COLUMN_NAME, uQb);
List<UnitResult> results = urQb.query();

Post a Comment for "How To Build Query With Selecting By Value Of Foreign Object's Field"