如何在Firebase中提出学生和教师关系?

时间:2016-09-13 15:01:49

标签: firebase firebase-realtime-database nosql

我正在尝试为学生创建基本数据结构 - >老师关系。

  • 学生 - >老师(多对多)

每个学生都可以有很多老师

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]

或者可以像这样改变结构

Users:

Teachers:

Relation:

这是Firebase的良好数据结构吗?我应该像这样分离关系节点吗?如果您有更好的想法,请告诉我您的数据结构!

1 个答案:

答案 0 :(得分:0)

要么是真的很好,如果我不需要特定数据(关系),我可能会使用类似的用户/教师/关系,我会节省数据库使用。我的建议是

{
    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
        }
    }
}