How to build query with selecting by value of foreign object's field

前端 未结 1 630
故里飘歌
故里飘歌 2021-01-19 02:50

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

1条回答
  •  走了就别回头了
    2021-01-19 03:11

    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 our sub-query on the Unit table first
    QueryBuilder uQb = unitDao.queryBuilder();
    uQb.where().eq(Unit.TYPE_FIELD_NAME, UnitType.JUICES);
    // outer query on UnitResult table
    QueryBuilder urQb = unitResultDao.queryBuilder();
    // in using the sub-query
    urQb.where().in(UnitResult.UNIT_COLUMN_NAME, uQb);
    List results = urQb.query();
    

    0 讨论(0)
提交回复
热议问题