如何使用ActiveAndroid加载整个对象(带列表)
我有一个简单的模型:如何使用ActiveAndroid加载整个对象(带列表),android,sql,sqlite,activeandroid,Android,Sql,Sqlite,Activeandroid,我有一个简单的模型: @Table(name = "Books") public class Book extends Model { @Column(name = "title") String title; //Variable to cache the pages List<Page> pages; public Book(){ } public List<Page> getPages() {
@Table(name = "Books")
public class Book extends Model {
@Column(name = "title")
String title;
//Variable to cache the pages
List<Page> pages;
public Book(){
}
public List<Page> getPages() {
if (pages==null) pages=getMany(Page.class, "book");
return pages;
}
}
我遇到的问题是,我想将整个book对象(及其所有子对象)序列化为JSon(使用GSon),在检索对象时,这些对象没有加载
public String toJSon(long id){
Book b = new Select().from(Book.class).where("id = ?", id).executeSingle();
// At this point, the array of pages is obviously empty, and I don't want to hard-call "getPages" because in the future every page will have words, and I would then have to iterate every page, etc..
Gson gson = new GsonBuilder().create();
return gson.toJson(b);
}
如何一次加载Book对象及其所有页面
public String toJSon(long id){
Book b = new Select().from(Book.class).where("id = ?", id).executeSingle();
// At this point, the array of pages is obviously empty, and I don't want to hard-call "getPages" because in the future every page will have words, and I would then have to iterate every page, etc..
Gson gson = new GsonBuilder().create();
return gson.toJson(b);
}