如何在Ormlite中将ForeignCollection字段放入游标中 [英] How to get ForeignCollection Field into Cursor in Ormlite
问题描述
我的下表中有一个ForeignCollection
字段:
I have a ForeignCollection
field in my table below :
@DatabaseTable(tableName = "json_main")
public class JsonMain {
@DatabaseField( id = true)
int _id;
@DatabaseField
int likes_count;
@DatabaseField
String protected_visibility;
@ForeignCollectionField
ForeignCollection<JsonUser> jsonUser = null;
}
此表的参考:
@DatabaseTable (tableName = "json_main_user")
public class JsonUser {
@DatabaseField(generatedId = true)
public int _id;
@DatabaseField(foreign = true, foreignAutoRefresh = true, columnName = "parent_id")
private JsonMain jsonMain;
}
我正在建立查询以在此处获取光标:
I'm Building My Query to get The cursor here :
QueryBuilder<JsonMain, Integer> queryBuilder_main = dao_json_main.queryBuilder();
PreparedQuery<JsonMain> jsonMains_list =queryBuilder_main.orderBy("sort_id",false).prepare();
CloseableIterator<JsonMain> closeableIterator = dao_json_main.iterator(jsonMains_list);
AndroidDatabaseResults androidDatabaseResults= (AndroidDatabaseResults)closeableIterator.getRawResults();
Cursor cursor = androidDatabaseResults.getRawCursor();
我已将数据正确插入数据库中
我想知道如何使用Cursor
或ormlite使用json_main表的ForeignCollection
.以上是我尝试过的.
I have inserted the Data Correctly into Database
I want to Know How could I get ForeignCollection
of json_main table using ormlite using Cursor
.Above is what I have tried .
高度赞赏任何答案或建议
Any Answer or Suggestion is Highly Appreciated
推荐答案
我已经正确地将数据插入到数据库中,我想知道如何使用Cursor或ormlite使用Ormlite获取json_main表的ForeignCollection.
I have inserted the Data Correctly into Database I want to Know How could I get ForeignCollection of json_main table using ormlite using Cursor .Above is what I have tried .
我希望我理解这个问题. JsonMain
Cursor
没有JsonUser
表中的任何信息.它具有的是_id
字段,该字段与JsonUser
表中的jsonMain_id
字段相对应.您可以做的是使用_id
并在JsonUser
表上进行查询以获取关联的用户.
I hope I understand the question. The JsonMain
Cursor
doesn't have any information from the JsonUser
table. What it does have is the _id
field which corresponds to the jsonMain_id
field which is in the JsonUser
table. What you can do is take that _id
and do a query on the JsonUser
table to get the associated users.
执行此操作的唯一另一种方法是构造您自己的JOIN
原始查询,该查询在一个游标中同时返回主字段和用户字段.不幸的是,在这种情况下, ORMLite 不会有太大帮助.
The only other way to do this would be to construct your own JOIN
raw query which returns both the main fields and the user fields in one cursor. Unfortunately ORMLite won't help much in this scenario.
这篇关于如何在Ormlite中将ForeignCollection字段放入游标中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!