如何找到与轨道.js的链接关系



我似乎无法弄清楚如何让链接对象在轨道上工作.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'
    }
  }
};

如何访问学生的家庭作业?

对我来说

,看起来你想做的是

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

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

最新更新