Multiple toMany relationships to a single table

喜夏-厌秋 提交于 2019-12-07 06:26:00

问题


I'm new to greenDAO and I'm working on writing the DaoGenerator. One issue that I've run into is that I have a user table and a wallpost table. I would like to be able to have two columns in the wallpost table that are toMany relations to the user table (the wall owner and the posting user) they may or may not be the same user, but so far it doesn't look like it is possible to have two toMany relations that point to a single table in the same table.

Is there a better way to do this/a way to make this possible? I'm hoping to be able to load the wall posts and fetch the wall owner and posting user by calling .getOwner() and .getPoster().

Thanks


回答1:


You must set names for the relations. Have a look at the (just improved) section called Relation Names and multiple Relations of the documentation on relations. It comes with an example:

Property pictureIdProperty = user.addLongProperty("pictureId").getProperty();
Property thumbnailIdProperty = user.addLongProperty("thumbnailId").getProperty();
user.addToOne(picture, pictureIdProperty);
user.addToOne(picture, thumbnailIdProperty, "thumbnail");


来源:https://stackoverflow.com/questions/13257872/multiple-tomany-relationships-to-a-single-table

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