How to come up with students and teacher relation in Firebase?

送分小仙女□ 提交于 2020-01-07 04:58:27

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!