【问题标题】:How to find a linked relationship with Orbit.js如何找到与 Orbit.js 的链接关系
【发布时间】:2018-06-02 16:09:45
【问题描述】:

我似乎无法弄清楚如何让链接对象在 Orbit.js 中工作。我已经将源代码通读了几千遍(并不夸张:D),但没有任何文档。

我试过了:

memoryStore.findLinked("student", 1, "homeworks")

但返回错误:

Uncaught Error: OC.LinkNotFoundException: student/1/homeworks

我的学生架构如下所示:

PlanHW.models.schema.student = {
  attributes: {
    username: {
      type: 'string'
    }
    //...
  },
  links: {
    homeworks: {
      type: 'hasMany',
      model: 'homework',
      inverse: 'student'
    }
  }
};

作业模式如下所示:

PlanHW.models.schema.homework = {
  attributes: {
    title: {
      type: 'string'
    }
    //...
  },
  links: {
    student: {
      type: 'hasOne',
      model: 'student',
      inverse: 'homeworks'
    }
  }
};

如何访问学生的作业?

【问题讨论】:

    标签: javascript orbit.js


    【解决方案1】:

    在我看来,你想做的是

    store.query(q => q.findRelatedRecords({type: 'student', id: student.id}, 'homeworks')
    

    这将为您提供属于该学生的所有作业。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-06-13
      • 1970-01-01
      • 2020-05-19
      • 1970-01-01
      • 2017-07-01
      • 2021-09-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多