来自多个表的SugarORM查询? [英] SugarORM query from multiple tables?

查看:256
本文介绍了来自多个表的SugarORM查询?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将SugarORM用于我的Android应用程序.在我的项目中,我有几个表,我想知道是否有一种方法可以将它们连接到另一个具有多个表中的列的类对象中?

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.

推荐答案

SugarORM提供了用于简单查询的查询生成器对象.由于它不为连接提供支持,因此您可以直接执行原始查询,并将结果存储到临时创建的对象中.

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.

因此,构建您的自定义原始查询,重命名SELECT部分​​中的字段

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
}

这里是文档:

如何在sugarORM中执行查询

这篇关于来自多个表的SugarORM查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆