问题
I am trying to create just basic data structure for students -> teacher relation.
- Students -> Teacher (many to many)
Each students can have many teachers
Users
uid1:
type: student
name: Alex Smith
teachers: [uid5: true, uid4: true ] //is it better to do it like this?
uid2:
type: student
name: Michael A
teachers: [ uid5: true]
uid3:
type: student
name: Michael A
teachers: [uid5: true]
uid4:
type: teacher
name: Alex Smith
teacher: [uid3: true] //is it better to use their uid?
uid5:
type: teacher
name: Teacher 1
students: [uid1: true, uid2: true]
or May be change the structure like this
Users:
Teachers:
Relation:
Is this good data structure for Firebase? Should I separate the relation node like this? Please give me your data structure if you have better idea!
回答1:
Either is fine really, I'd probably go with something similar users/teachers/relation as that way if I didn't need specific data (The relations) I'd save on database usage. My suggestion would be
{
users: {
userId1: {
name: 'Mat'
},
userId2: {
name: 'Barb'
}
},
teachers: {
teacherId1: {
name: 'Phil'
},
teacherId2: {
name: 'Steph'
}
},
userTeachers: {
userId1: {
teacherId1: true,
teacherId2: true
},
userId1: {
teacherId1: true
}
},
teacherUsers: {
teacherId1: {
userId1: true,
userId2: true
},
teacherId2: {
userId1: true
}
}
}
来源:https://stackoverflow.com/questions/39473242/how-to-come-up-with-students-and-teacher-relation-in-firebase