问题
I am using SugarORM for my Android application. In my project I have couple of tables and I was wondering is there a way to to join them into another Class Object that has columns from multiple tables?
If yes, then example would be very helpful.
回答1:
SugarORM provides a Query Builder object for simple queries. Since it doesn't provide supporto for joins, you can directly execute a raw query and store the result into an object created ad-hoc.
So, build your custom raw query renaming the fields in the SELECT part
CustomOBJ.executeQuery("SELECT tableA.fieldA as field1, tableA.fieldB as field2, tableB.fieldA as field 3 FROM tableA JOIN tableB WHERE .....");
and then create your custom object
public CustomOBJ {
private String field1;
private String field2;
private String field3;
public CustomOBJ(){} //you must declare an empty constructor
//getters
//setters
}
Here the documentation:
raw queries with joins in sqlite
how to execute queries in sugarORM
来源:https://stackoverflow.com/questions/35534733/sugarorm-query-from-multiple-tables