如何使用除主键之外的源属性在GreenDAO中进行多对多关系查询?

Bri*_*off 5 sqlite android android-sqlite greendao greendao3

假设我们有以下实体:项目:

class Item {
...
    @Index(unique=true)
    private String guid;
...
    @ToMany
    @JoinEntity(entity = JoinItemsWithTags.class, sourceProperty = "itemGuid", targetProperty = "tagName")
    private List<Tag> tagsWithThisItem;
    ...
}
Run Code Online (Sandbox Code Playgroud)

标签:

class Tag {
    @Id
    private Long localId;
    @Index(unique = true)
    private String name;
    ...
}
Run Code Online (Sandbox Code Playgroud)

我们需要加入他们.这是我的连接实体类:

@Entity(nameInDb = "item_tag_relations")
class JoinItemsWithTags {
    @Id
    private Long id;
    private String itemGuid;
    private String tagName;
    ...
}
Run Code Online (Sandbox Code Playgroud)

我想使用标记名称作为连接属性而不是Long id,因为在与服务器同步时更容易支持一致性.但是当前Item类中的标签getter总是返回一个空列表.我查看了日志并找到了在getter中内部使用的生成查询:

SELECT * <<-- there were a long sequence of fields
FROM "tags" T  JOIN item_tag_relations J1 
ON T."_id"=J1."TAG_NAME" <<-- here is the problem, must be `T."NAME"=J1."TAG_NAME"` 
WHERE J1."ITEM_GUID"=?
Run Code Online (Sandbox Code Playgroud)

所以问题是join是基于tag的_id字段.生成的List<Tag> _queryItem_TagsWithThisItem(String itemGuid)方法隐式使用该id进行连接:

// this `join` nethod is overloaded and pass tag's id as source property
queryBuilder.join(JoinItemsWithTags.class, JoinItemsWithTagsDao.Properties.TagName)
                    .where(JoinItemsWithTagsDao.Properties.ItemGuid.eq(itemGuid));
Run Code Online (Sandbox Code Playgroud)

我认为正确的方法可能是以下情况:

// source property is passed explicitly
queryBuilder.join(/* Desired first parameter -->> */ TagDao.Properties.Name,
    JoinItemsWithTags.class, JoinItemsWithTagsDao.Properties.TagName)
                    .where(JoinItemsWithTagsDao.Properties.ItemGuid.eq(itemGuid));
Run Code Online (Sandbox Code Playgroud)

但是这个代码是生成的dao,我不知道如何用它做任何事情.有没有办法解决这个问题?