我有以下类型的表
实体
|id|title|entity_authors
|id|authorName|entity_to_authors
|id|entityId|authorId|我设法连接到了表entity和entity_to_authors
r.table("entity")
.get("f17234b6-b25c-4037-8dd1-314841967964")
.merge({e -> r.hashMap("entity_to_authors", r.table("entity_to_authors").filter(r.hashMap("entityId", e.g("id"))).coerceTo("array"))})
.run<Unit>(connection)现在我需要从表entity_authors中获取数据我是这样做的(但这是错误的)
r.table("entity")
.get("f17234b6-b25c-4037-8dd1-314841967964")
.merge({e -> r.hashMap("entity_to_authors", r.table("entity_to_authors").filter(r.hashMap("entityId", e.g("id"))).coerceTo("array"))})
.merge({e -> r.hashMap("entity_authors", r.table("entity_authors").filter(r.hashMap("id", e.g("entity_to_authors").nth(0).g("authorId"))).coerceTo("array"))})
.run<Unit>(connection)由于这里我使用nth(0)来获取从entity_to_authors收到的第一行数据,我应该怎么做才能获得所有的作者呢?
对不起,我的英语!
发布于 2018-03-23 00:16:05
有人告诉我这是这样做的:
.merge{ row -> r.hashMap("entity_authors", r.table("entity_authors") .filter { ea -> row.g("entity_to_authors").g("authorId").contains(ea.g("id")) } .coerceTo("array"))}
https://stackoverflow.com/questions/49425839
复制相似问题