思维模型上的多个'belongsTo'关系

时间:2015-03-28 22:45:26

标签: orm relationship rethinkdb thinky

我有两个模型,User和Capture,其中Capture可以与多个用户相关:它由三个不同的用户拥有,声明和处理。

User = thinky.createModel 'User',
    id:           String
    displayName:  String
    email:        String

Capture = thinky.createModel 'Capture',
    id: String
    ownerID: String
    processedByID: String
    claimedByID: String
    created: Date
    updated: Date

Capture.belongsTo User.model, 'owner', 'ownerID', 'id'
Capture.belongsTo User.model, 'processedBy', 'processedByID', 'id'
Capture.belongsTo User.model, 'claimedBy', 'claimedByID', 'id'

所有者关系有效,但我无法获得processedBy和claimBy关系。我正在查询.getJoin(),并且Thinky已经在我的表上创建了二级索引(所以它至少知道关系)

我做错了什么?如何在查询中返回嵌套对象?

1 个答案:

答案 0 :(得分:3)

那是因为thinky默认会加入另一个模型(以避免循环引用)。 您必须明确要获取的链接:

 Capture.getJoin({owner: true, processedBy: true, claimedBy: true}).run()
相关问题