0

我在 android 中使用 ormlite。图书馆似乎很有帮助,但我对 QueryBuilder 有疑问。我将尝试用一些抽象的例子来解释这一点。假设我们有 4 个表:Projects、Employees、Country、ActiveProject。单个项目可以有多个员工,但员工只能在一个项目上工作。员工来自一个国家。ActiveProject 表有一行表示当前活动的项目。

现在我想列出来自指定国家(“en”)的所有员工,这些员工为当前活动的项目工作。

//retrieving Daos:
Dao<Projects, Long> projectDao = helper.getDao(Projects.class);
Dao<Employees, Long> employeeDao = helper.getDao(Employees.class);
Dao<Countries, Long> countryDao = helper.getDao(Countries.class);
Dao<ActiveProject, Long> activeProjectDao = helper.getDao(ActiveProject.class);

//retrieving QueryBuilder
projectQb = projectDao.queryBuilder();
employeeQb = employeeDao.queryBuilder();
countryQb = countryDao.queryBuilder();
activeProjectQb = activeProjectDao.queryBuilder();

//constructing query:
//add WHERE statement for country
countryQb.where().eq(Countries.NAME,"en");
employeeQb.join(countryQb);
//so far so good, when I query from employees here, I'll get all employees from "en"

//limit the results to active project only
projectQb.join(activeProjectQb);
//if I query the projectQb for all projects, I'll get only the active one - as expected.
//but here the problem starts
employeeQb.join(projectQb);

现在,employeeQb.query() 将列出属于活动项目的所有员工,但来自所有国家。“Employees-Country join”和“WHERE”语句已经消失。

我在这里做错了吗?

4

1 回答 1

3

Unfortunately, at this time, ORMLite only supports JOINs with a single other table. Multi-table joins are not supported at this time. Feel free to add an item to the feature request part of the SourceForge site.

If you need to do the multi-table join then you can use the raw query functionality but you will have to interpret the results yourself.

于 2012-11-19T03:38:40.473 回答