How to find a linked relationship with Orbit.js

291 views Asked by At

I cannot seem to figure out how to get linked objects working in Orbit.js. I've read through the source code a few thousand times (not an exaggeration :D), and there is no documentation.

I've tried:

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

but that returns the error:

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

My schema for the student looks like this:

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

And the homework schema looks like this:

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

How can I access the student's homeworks?

1

There are 1 answers

0
morgler On

To me it looks like what you want to do is

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

This would give you all homeworks belonging to this student.