我在尝试在 Firebase 中构建我的数据然后检索它时遇到问题,以满足此用例:
我有“用户”和“组”
{
Users:
LpWgezRkC6EWS0sjXEWxhFl2: {
userName: 'John Doe'
etc...
}
},
Groups:
12345: {
PropertiesID: 78765,
GroupName: 'MyPool',
GroupOwner: 'LpWgezRkC6EWS0sjXEWxhFl2'
GroupPassword: 'jkhdfjkhfdkjhdfkjhfsae4euhh4FDDC'
etc...
}
}
任何用户都可以加入任何群组。
我将这种用户配对(关系)存储在“UserInGroups”节点中。
{
UsersInGroups: {
DUmwewIfzAbfWZN4NjS8mhX82: { <- UserId
12345: true <- GroupId
},
LpWgezRkC6EWS0sjXEWxhFl2: {
12345: true
}
}
}
最后,每个组都有一个“属性”节点,用于控制组的细节/行为。
{
Properties:
78765: {
PropertyName: 'Custom',
dateCreated: '20170601',
etc...
},
76421: {
PropertyName: 'Admin',
dateCreated: '20170602',
etc...
}
}
综上所述,我的应用程序有一个仪表板 View ,它在 UICollectionView 中显示所有组/属性信息。它应该显示如下信息:
- 组名
- GroupOwner
基于“群组”节点中的 PropertiesID
属性名称
属性创建日期
我将如何“加入节点”以便我能够检索组信息以及属性信息;
基于登录到应用程序的用户是否属于组(因此在 UsersInGroups 节点中有一个条目)?!
UPDATE
关于数据结构的后续问题...
进行三 (3) 次连接以获取我希望在 UIColloection View 中显示的所有信息是否可以接受。
像这样:
let ref = firebase.database().ref("UsersInGroups")
ref.child((Auth.auth().currentUser?.uid)!).queryEqual(toValue: true).observe(.value, with: { snapshot in
let groupsRef = firebase.database().ref("Groups")
groupsRef.child(snapshot.key).observe(.value, with: { snap in
let propertiesRef = firebase.database().ref("Properties")
ref.child(snap.key).queryEqual(toValue: true).observe(.value, with: { gamesnapshot in
//Get all the info from firebase
})
})
})
最佳答案
在您下载“群组”节点的所有地方,您是否需要该特定群组的属性?如果这样做,您可以在“组”中创建一个新节点,将其称为属性,并在其中列出所有属性。
关于ios - Firebase 加入多个节点对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44533078/