What I would do that is to have two separate object stores inside of your database, one which represents teachers
and one which represents students
.
Then I'd store a teacher
object like:
{
name: 'John Smith',
subject: 'Maths',
students: [1,2,3,4,5]
}
Then I'd have a store for students
like:
{
id: 1,
name: 'Jane Doe'
}
I'd then have an id
key path in both stores (autogenerated or not, depending on whether it syncs somewhere) so you have a unique identifier of what the data is.
Finally you can create an index
on the students
property of a teacher and set the multiEntry
flag to true
so that it is known to be an array and you can query the object store on it as an array, see here for more info on multiEntry
indexes.
Note: At time of writing IE10 & IE11 do not support multiEntry
indexes in IndexedDB.