多toMany关系到单个表 [英] Multiple toMany relationships to a single table

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

问题描述

我是新来的 greenDAO 以及我正在写DaoGenerator。我碰到的一个问题是,我有一个用户表和wallpost表。我希望能有在wallpost表两列是toMany关系到用户表(墙所有者和发布用户),他们可能会或可能不会是相同的用户,但到目前为止,它看起来并不像有可能有两个toMany关系指向单个表中的相同的表。

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.

有没有更好的办法做到这一点/一种方式来实现这一目标?我希望能够通过调用.getOwner()和.getPoster()加载在墙上的职位,并获取墙壁所有者和发布用户。

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().

感谢

推荐答案

您必须设置关系的名称。看看所谓的关系的名称和关系上的文档的多重关系的(只是改善)部分。它配备了一个例子:

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");

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

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