Greendao:嵌套的实体和关系

时间:2017-08-21 07:45:38

标签: android sqlite entity greendao

所以我有这个场景:

实体Post有一个嵌套的Author实体。这是多对一关系,因为单个Post可以创建多个Author

public class Post{
@Id
long id;

long authorId;
@ToOne(joinProperty = "authorId")
Author author;
}

public class Author{
@Id
long id;
//This is useless for greendao. I have it here because it flows from the REST endpoint.
long postId;
}

当我从REST端点获得响应时,Post实体将与Author实体一起被拉出。 Post实体中的authorId不会从REST端点流出。

问题

  • 当我将Post实体持久保存到sqlite DB时,只会推送Post实体的字段。 Author实体未被推送。我尝试在authorId实体上设置Post,但没有任何运气。我错过了什么?

1 个答案:

答案 0 :(得分:0)

有同样的问题。看起来GreenDao无法自动在表格中插入内部对象。您需要通过authorDao在作者表中插入作者manualy。

相关问题