首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >重新思考多对多关系

重新思考多对多关系
EN

Stack Overflow用户
提问于 2018-03-22 18:10:02
回答 1查看 55关注 0票数 0

我有以下类型的表

实体

代码语言:javascript
复制
|id|title|

entity_authors

代码语言:javascript
复制
|id|authorName|

entity_to_authors

代码语言:javascript
复制
|id|entityId|authorId|

我设法连接到了表entityentity_to_authors

代码语言:javascript
复制
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中获取数据我是这样做的(但这是错误的)

代码语言:javascript
复制
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收到的第一行数据,我应该怎么做才能获得所有的作者呢?

对不起,我的英语!

EN

回答 1

Stack Overflow用户

发布于 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"))}

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49425839

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档