SugarORM query from multiple tables?

旧城冷巷雨未停 提交于 2019-12-07 16:11:57

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!